.WAV PCM unsigned 8 bits mono data block to speaker

I want to understand the concept of sending wave file sound data to ATmega328P to drive a 8ohm 2W speaker.

I aware there is TMRpcm library but without understanding the WAVE format and sound concept is hard read the code and it is using Timer, which another stuff to learn.

I have extracted the .WAV PCM unsigned 8 bits data block and below is information:

           filename: [helloworld.wav]
           filesize: [8750]
                 id: [RIFF]
               size: [8742]
               type: [WAVE]
           chunk_id: [fmt ]
         chunk_size: [16]
             format: [1]
            channel: [1]
     sample_per_sec: [11025]
 average_bytes_per_sec: [11025]
        block_align: [1]
    bits_per_sample: [8]
            data_id: [data]
          data_size: [8706]
          data_block ........


  1. is the .WAV data block a RAW format data ?

  2. Since the bits_per_sample is 8 bits, let's say the first byte of data block is 0x41, 01000001 in binary. If to send this 8 bits data byte 0x41 to turn ON/OFF pulse to a GPIO pin that connected to speaker, the bits order should it starts from left-to-right or right-to-left ?

                      left-to-right --->> ?
                    0 1 0 0 0 0 0 1 ----------------> ATmega328P PWM pin -------------> 8 ohm 2W speaker
           ? <<---   right-to-left
  3. I wrote a program before to send RAW .snd speech data by turning ON/OFF the PIC port to create sound on the PC internal speaker ( during 90's ) during MSDOS day but I am unsure under Arduino platform, the .WAV PCM unsigned 8 bit mono data block is RAW format or not ?

Any guideline or reference is greatly apprieciated.

Please advise.

Yes it's bytes, and with 8-bit WAVs 1 byte represents one sample. 8-bit WAV files use unsigned data so the values are biased and silence is a series of bytes with a value of 128. 16 & 24-bit WAVs use signed values so silence is zero.

That seems similar to TMRpcm. Of course, you can't send the binary data directly to the speaker. You can, but it will sound like random noise.

Normally, with a DAC, you'd send a value of 41 hex which is 25% or 1.25V on a 5V scale). TMRpcm sends a high-frequency PWM value of 41 which means an average of about 1.25V for the duration of the sample.

And in case you don't know this, the Arduino can't directly drive a speaker. You need an amplifier or driver circuit, or you can use powered computer speakers. (The minimum load is 125 Ohms.)

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.