Getting data from WAV into a buffer: Is that a read, copy or parse?

Thread Starter

richard3194

Joined Oct 18, 2011
179
Hi. I'm a beginner in C programming and getting an MCU to play WAV files. The objective, very often (if not always, I'm not sure) is to get the data (samples) that reside within the WAV file, in say SD memory, into a bufffer, whence it is taken up by a ADC, whose output is analogue. In an example of a WAV player that is before me, I see that this process begins when the function "play ()" is called. As I understand it, that process is a read operation. But, I wonder whether it's parsing or even copying. Also, I assume that if "play ()" is a special read function, inasmuch as it's only to be used to read audio files, nothing else. Is there anything to say about differences in read, parsing and copying? Thanks. Rich
 

Thread Starter

richard3194

Joined Oct 18, 2011
179
Hi. In the code I'm looking at, I think I'm making the error of thinking "play()" is a fuction that is part of a library, when it fact it's a user defined function. And the code in the user defined function is executed when "play()" is called. But, anyway, as I understand it, the effect of calling "play()" should be to get data from the WAV file into the buffer. And, unless I'm mistaken, the operation is a read operation. Unless it's got some other name. Rich
 

djsfantasi

Joined Apr 11, 2010
9,163
Hi. I'm a beginner in C programming and getting an MCU to play WAV files. The objective, very often (if not always, I'm not sure) is to get the data (samples) that reside within the WAV file, in say SD memory, into a bufffer, whence it is taken up by a ADC, whose output is analogue. In an example of a WAV player that is before me, I see that this process begins when the function "play ()" is called. As I understand it, that process is a read operation. But, I wonder whether it's parsing or even copying. Also, I assume that if "play ()" is a special read function, inasmuch as it's only to be used to read audio files, nothing else. Is there anything to say about differences in read, parsing and copying? Thanks. Rich
First, you may get confused by your misuse of a term. When reading a .wav file into a buffer, it is whence sent to a DAC (digital to analog converter) and not an ADC (analog to digital converter). Does this make sense?
 

trebla

Joined Jun 29, 2019
543
If the DAC can use direct data from WAV file, then is only reading from SD memory and copying to DAC buffer needed. Often you need also make some conversions to align readed WAV data to DAC input format. However, your hypothethical read() function can do that also.
 

Thread Starter

richard3194

Joined Oct 18, 2011
179
First, you may get confused by your misuse of a term. When reading a .wav file into a buffer, it is whence sent to a DAC (digital to analog converter) and not an ADC (analog to digital converter). Does this make sense?
Understood. I know it's a DAC, just put ADC for some silly reason. :)
 

Thread Starter

richard3194

Joined Oct 18, 2011
179
Hi. I think I'm being a bit myopic in my initial thinking. Because I think calling "Play()", should involve a read and a write, not just a read. I don't know how useful or relevant it is, to bring into the discussion Copy and Paste, but in Windows, a Copy and Paste involves a read and a write, which leaves the original file intact. Cut and Paste also involves a read and write, but the original file is deleted, so it's Move operation. So, when "play()" is called, there is, at some point in the code, a read of the data in the WAV file. I'm presuming that to get that data into say a buffer involves a write operation. I'm sure about a read operation, not so sure whether there is a write operation invloved. I'm just assuming there is. If so, the read & write would (in my mind) be akin to a copy operation.
 
Last edited:

trebla

Joined Jun 29, 2019
543
You can think about your player as system with different memory locations. Then your play() function reads a chunk of data (byte, word etc) from SD card and copies it to DAC buffer. If this function does not special (intended) write or erase operation on SD card then the source data remain intact. If readed data needs to be modified (aligned) for DAC then this is done in another RAM buffer variable. Modifying data (writing to) SD card memory is very slow process compared to RAM operations and playing WAV files needs high speed operations from MCU.
 

WBahn

Joined Mar 31, 2012
30,062
Hi. I think I'm being a bit myopic in my initial thinking. Because I think calling "Play()", should involve a read and a write, not just a read. I don't know how useful or relevant it is, to bring into the discussion Copy and Paste, but in Windows, a Copy and Paste involves a read and a write, which leaves the original file intact. Cut and Paste also involves a read and write, but the original file is deleted, so it's Move operation. So, when "play()" is called, there is, at some point in the code, a read of the data in the WAV file. I'm presuming that to get that data into say a buffer involves a write operation. I'm sure about a read operation, not so sure whether there is a write operation invloved. I'm just assuming there is. If so, the read & write would (in my mind) be akin to a copy operation.
Yes, your play() function is going to involve both read (from the file) and write (to the DAC buffer) operations, probably with some translation along the way. It will likely have to do some other things, as well, but that depends on who wrote the play() function and how it fits into how they parsed the bigger problem of playing a WAV file, such as opening the file and reading the header information and initializing the DAC and the buffer and managing the data flow such as setting up interrupts to ensure that data is fed into the buffer fast enough to over buffer underflows.
 

Thread Starter

richard3194

Joined Oct 18, 2011
179
Hi. As to memory: I see that the MSP430FG series of MCUs, the literature tells me the DAC input register named DAC12_0DAT (in MCU flash memory) is at location: Base Address 0780h, Offset 04h. That will be a permanent address for the DAC input register I'm assuming. So, whatever reads the data from the WAV file and writes to the DAC input register, must discover both the read address (say in SD card) and the write address (MCU flash memory). Any hints about this? Rich
 

trebla

Joined Jun 29, 2019
543
DAC12_0DAT is not in flash memory, it is in special function register area in RAM. Flash is mainly used for storing your program code.

Your SD card reading routine must be aware of SD card memory organization or using some file system for this card. For writing to DAC register you show the destination addres and DAC triggering sequence in your program code. That means, pointing to correct addresses are program authors (yours) responsibility.
 
Top