Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

This is an example of the  8-bit PCM audio playback using PSoC4200M and CY8CKIT-044 Pioneer Board.

Audio data are stored in the PSoC FLASH in 8-bit signed PCM format, and sent to IDAC on the interrupt at 5.5kHz or 11kHz update rate. The project  doesn't use DMA. The IDAC is configured in bidirectional mode (sink and source), corresponding to the sign of the data. The IDAC current is converted into voltage output using an Opamp operating in transimpedance mode. Opamp output is centered around voltage reference Vdd/2.

For sound generation, the output was directly connected to the headphones with combined impedance of 64oHm (32+32). 

The sound starts playing when the onboard switch button (SW2) is  pressed, which enables the update interrupt. Once all of the data has been played, the sound stops. Pressing the button again during playback restarts it from the beginning.

The button events are captured using a ButtonSw32 custom debouncer component, utilizing a WDT0 timer for polling the pins state. The debouncer is set for the external interrupt, and pins state is processed using interrupt callback procedure, automatically clearing the interrupt source. The ButtonSw32 component is included into the project.

The project includes several test audio files in 8-bit signed format:
sawtooth_8-bit_S.h                              - test sawtooth
smb_world_clear_5k5_N_S.h          -Super Mario theme, 5.512kHz, Normalized, Signed (size=33512 bytes)
smb_world_clear_5k5_ND_S.h      - Super Mario theme, 5.512kHz, Normalized and D-compressed (size=33608 bytes)
smb_world_clear_11kHz_N_S.h    - Super Mario theme, 11.025kHz, Normalized (size=67064 bytes)
smb_world_clear_11kHz_ND_S.h - Super Mario theme, 11.025kHz, Normalized and D-compressed (size=67064 bytes)


The Super Mario theme produced about 5.5 sec playback with reasonable quality at both 5.5kHz and 11kHz update rate. PSoC4 FLASH used was 28% for 5.5kHz files, and 54% for 11kHz files accordingly.

The WAV files have been converted to the C/H code using  WAVtoCode v1.1.1 by Colin Seymour.

The original WAV data have been Normalized to fill the entire 8-bit scale, which increased the dynamic range.  For testing purposes some files were additionally D-compressed (log-trimmed) using the BTc SoundEncoder v3.0 by Roman Black, which can further increase the fullness of the sound.

Project attached contains all necessary files. It was tested using both Creator 4.0 and 4.4. 

     WAVtoCode v1.1.1 by Colin Seymour:         https://colinjs.com/software.htm#t_WAVToCode
     BTc SoundEncoder v3.0 by Roman Black:  http://www.talkbotbrain.com/


Figure 1. Project schematic. The PCM data are fed from FLASH to the IDAC on isrTimer interrupt. The IDAC operates in both sink and source modes, updating the mode according to the data sign. The Opamp operates in transimpedance mode with feedback resistor 3.3k, producing +/-1V peak amplitude at full scale around the the reference Vdd/2.


Figure 2. Custom debouncer component ButtonSw32, which captures SW2 button events and starts the playback. 


Figure 3. Project annotation using the PSoC Annotation Library v1.0 and KIT-044. The reference voltage Vdd/2 was pulled from the onboard hidden Pin_5[0], reserved for the light sensor. Capacitors C1 and C2 are optional.


Figure 4. Screenshot of the sample audio playback at 5.5kHz.


Figure 5. Screenshot of the test sawtooth playback at 5.5kHz.


1 Reply
50 likes received 250 replies posted 100 solutions authored

Hi @odissey1 ,

Thanks for sharing this with the community!

Kind Regards

Arpit Srivastav