Comments (17)
I had the same problem.
Thanks to codeium.com IA, I solved it this way:
void AudioZeroClass::play(FsFile myFile) {
to
void AudioZeroClass::play(FsFile& myFile) {
from sdfat.
Ok, compiler no not give me error, but function do not read the file.
I cannot find a solution.
from sdfat.
In the latest version of SdFat the copy constructor for File classes is private to prevent multiple copies of a file object.
A function with this signature will create copy of myFile on the stack.
void AudioZeroClass::play(FsFile myFile) {
This can cause bugs since the File object in the calling program is not updated.
With this call by reference only one copy of the file object exists:
void AudioZeroClass::play(FsFile& myFile) {
I you really want to have multiple, maybe inconsistent, copies of a file object you can edit SdFatConfig.h here.
from sdfat.
void AudioZeroClass::play(FsFile& myFile) {
By changing only the definition of audiozero, the file is played, but only the first time.
The following times it does not play.
As if close and open does not it restart.
In the previous version, this did not happen.
`void AudioZeroClass::play(File myFile) {
dacConfigure();
tcConfigure(__sampleRate);
__StartFlag = false;
while (myFile.available()) {
if (!__StartFlag) // Prima volta
{
__SampleIndex = 45; // 45 byte sono l'Header del Wav con le informazioni
myFile.read(__WavSamples, __NumberOfSamples);
__HeadIndex = 0;
/*once the buffer is filled for the first time the counter can be started*/
tcStartCounter();
__StartFlag = true;
}
else // Successive volte
{
uint32_t current__SampleIndex = __SampleIndex;
if (current__SampleIndex > __HeadIndex) { //mentre esce il buffer salendo
myFile.read(&__WavSamples[__HeadIndex], current__SampleIndex - __HeadIndex);
__HeadIndex = current__SampleIndex;
}
else if (current__SampleIndex < __HeadIndex) { //Quando il puntatore dei dati che escono torna a zero
myFile.read(&__WavSamples[__HeadIndex], __NumberOfSamples -1 - __HeadIndex); // riempe la fine
myFile.read(__WavSamples, current__SampleIndex);
__HeadIndex = current__SampleIndex;
__HeadIndex = 0;
} // analogWrite(A0, __WavSamples[__SampleIndex++]<<2);
}
}
myFile.close();
delay(100);
tcDisable();
tcReset();
analogWrite(A0, 512);
}`
from sdfat.
By changing only the definition of audiozero, the file is played, but only the first time.
The following times it does not play.
As if close and open does not it restart.
This is because of the change from call by value to call by reference. The file object in the calling program now used instead of a copy so play now closes the file object in the calling program.
Generally having multiple copies of a file object for an open file causes bugs.
If you don't want to fix the multiple copy problem just edit SdFatConfig.h and allow multiple copies.
from sdfat.
How do I get the file to play again?
from sdfat.
How do I get the file to play again?
See the above link to the place to change in SdFatConfig.h.
from sdfat.
from sdfat.
at line 68 of SdFatConfig.h
change
#define FILE_COPY_CONSTRUCTOR_SELECT FILE_COPY_CONSTRUCTOR_PRIVATE
to
#define FILE_COPY_CONSTRUCTOR_SELECT FILE_COPY_CONSTRUCTOR_PUBLIC
from sdfat.
at line 68 of SdFatConfig.h change
#define FILE_COPY_CONSTRUCTOR_SELECT FILE_COPY_CONSTRUCTOR_PRIVATE
to
#define FILE_COPY_CONSTRUCTOR_SELECT FILE_COPY_CONSTRUCTOR_PUBLIC
Does this fix my issue too?
from sdfat.
FILE_COPY_CONSTRUCTOR_PUBLIC
looks like it did... now compiles without error.
from sdfat.
Does this fix my issue too?
It doesn't fix the fundamental issue of multiple copies of a file object but it will allow call by value.
from sdfat.
It's been a long time since I looked at my code, but am I creating multiple instances?
SdFat sd;
SdFile file;
File dir;
is SdFile an inherited class of File ?
By the way, I'm a novice at C++, so it's a miracle how I managed to get my coding working in the first place.
from sdfat.
is SdFile an inherited class of File ?
File is a typedef. The whole class structure has become very complex to allow SdFat to run on many boards. Many of the definitions are here.
There are two basic ways to create a copy of an object. The copy constructor which makes a copy on the stack for call by value.
void AudioZeroClass::play(FsFile myFile)
And the assignment operator:
File file = sd.open("name.txt", O_RDWR | O_CREAT);
File fileCopy = file; // second copy
The state of the file is in the File object so multiple objects for a file can cause problems. If one object is used for write and the file is closed with another object, file system corruption is likely.
from sdfat.
I had the same problem. Thanks to codeium.com IA, I solved it this way:
void AudioZeroClass::play(FsFile myFile) {
to void AudioZeroClass::play(FsFile& myFile) {
@gioreva BTW I added sdfat to the AudioZero library 5 years ago. Just interested re you using my library https://github.com/rickyelqasem/AudioZeroSdFat or did you modify it yourself?
from sdfat.
I think I made a lot of changes.
Especially to use more available wav, e.g. stereophonic, generated online.
But I haven't figured out how I can loop the playback, leaving SdFat private.
Now it only plays the message the first time.
from sdfat.
But I haven't figured out how I can loop the playback, leaving SdFat private.
Now it only plays the message the first time.
I would put a rewind at the start of void AudioZeroClass::play(FsFile& myFile)
like this:
myFile.rewind();
and remove the myFile.close()
at the end.
from sdfat.
Related Issues (20)
- Did not work at ESP32-CAM HOT 6
- MMC_ERASE HOT 2
- Wrapper to fs::FS to use SDfat in ESPAsyncWebserver HOT 6
- pico-sdk only rp2040 implementation HOT 7
- ESP32 S3 always fails to mount card HOT 10
- Unable to format flat Spiflash module with ESP8266 HOT 4
- Mount issues for a Windows-formatted card HOT 35
- SD NAND XTSD01G (surface mounted chip) not formating HOT 1
- Unable to share the same SPI bus with TFT_eSPI on ESP32 HOT 1
- Problems with multiple SD card HOT 3
- Long timeout calling begin() on Teensy 4.1 when no card present HOT 5
- SdFat 2.22 with USER_SPI1 pin + another USER_SPI2 in SPI_Mode3 HOT 2
- Arduino-Pico: huge slowdown with v2.2.2 (vs.2.1.1) HOT 5
- Problem with SdFat and TwoWire instance. HOT 3
- sd.begin(SPI_CONFIG) breaks my DMA ADC datalogger on the SAMD51 HOT 5
- exFat sd cards not working with Sdinfo.ino example, only FAT32 card HOT 7
- Allocating bin file with 0s HOT 2
- CS_Pin has to be driven high on ESP32 (to be low at the SDCARD) because of some logic inbetween HOT 3
- Initialization fails with ESP32 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sdfat.