Play audio sample from eprom

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

cross mob
John-M
Level 1
Level 1
First like given 10 sign-ins First reply posted

Hi All,

New to the forum...

I was wondering how does one play samples? Looking at playing a raw audio sample from EPROM/SPI Flash to I2S or DAC.

Already looked at some older solutions which talked about Storing raw audio in EEPROM -> drive DMA with clock or PWM -> pipe DMA output to DAC but examples are nolonger availalable (on the old Cypress website)   

Idealy would like any examples or application notes on this.

Thanks

John

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.

Attached is updated project #57. It uses 1-bit encription of the Super Mario theme using BTc SoundEncoder 3.0 by Roman Black. 

The BTc SoundEncoder 3.0 can no longer be downloaded from the original website www.RomanBlack.com, but it can be found here: http://www.talkbotbrain.com/.

The conversion tool produces *.C file, which is not directly compatible with GNU C for PSoC and need to be manually updated. I used simple Find/Replace ->Replace all option of the Microsoft Write. The Creator's built-in option didn't work, as Creator permanently hangs and had to be closed.

 

//original *.C file produced by the BTc Sound encoder
//-------------------------------------------------- 
void sound_data1()    org (1 * 256) 
{ 
   asm retlw 0x95 ; 
   asm retlw 0x55 ; 
   asm retlw 0x55 ; 
   asm retlw 0x55 ; 
   asm retlw 0x55 ; 
...

//manually corrected *.h file for PSoC
//-------------------------------------------------- 
const uint8 sound_data[] = 
{ 
   0x95,
   0x55,
   0x55,
   0x55,
   0x55,
...

 

 There are some additional erroneous lines, which had to be manually deleted using Find->Delete process:

 

// original *.c file produced by BTc SoundEncoder 3.0
...
   asm retlw 0xFA ; 
   asm retlw 0x50 ; 
   // reserved for MikroC return!  
   //------------------------------------- 
} 
 
 
 
//-------------------------------------------------- 
void sound_data2()    org (8 * 256) 
{ 
   asm retlw 0x0C ; 
   asm retlw 0x90 ; 
   asm retlw 0x14 ; 
...

// manually modified by deleting }...{ sections
...
   0xFA, 
   0x50, 
   // reserved for MikroC return! // <-can leave that  
   //------------------------------------- // <-can leave that 
   0x0C, 
   0x90, 
   0x14, 
...

 

 

Using CY8CKIT-042 PSoC4200 Pioneer Board (FLASH size is 32k) allows for about 10 sec of the continuous sound using 22.050kHz playback rate. Resources consumption is: FLASH 66.8% / 39.9%.

Using CY8CKIT-044 PSoC4200M Board (FLASH size is 128k) the resources consumption is: FLASH 16.9% / SRAM 10%.

It is clear, that using traditional 8-bit PCM sound encoding is practically out of picture for KIT-042, and will barely make a 1-second squeak. One may consider KIT-044 (128k FLASH) for PCM encoding of ~5sec playback.

/odissey1

PS attached are: 1. project archive, 2. BTc SoundEncoder 3.0 archive, 3. BTc SoundEncoder 3.0 Help, 4. Super Mario theme original WAV file (6-sec playback). 

 

Figure 1. Project schematic. Note that the RC values used by the Matt Landrum in his project differ from the recommended by the BTc SoundEncoder.

Sounds_01a_A.png

 

Figure 2. Screenshot of the BTc SoundEncoder 3.0.

BTcSE30BETA.png

View solution in original post

10 Replies
ChristopherF_51
Employee
Employee
100 sign-ins 25 solutions authored 10 likes given

I'm not sure this will help, but a lot of the old Cypress code examples for PSoC Creator are listed here: https://www.infineon.com/cms/en/design-support/software/code-examples/psoc-4-code-examples-for-psoc-...

You can still use PSoC Creator if you want.

We also have code examples for ModusToolbox on GitHub here: https://github.com/Infineon/Code-Examples-for-ModusToolbox-Software

Look under Peripherals I think.

I don't know about app notes. Maybe someone else does.

0 Likes

Thanks for this.

Unfortunately thier are no Audio examples I can find in the Psoc4 Cypress code 😞

The examples on Git hub are mainly using a RTOS - relatly looking for examples on Psoc4 and bare metal.

Thanks

0 Likes
BiBi_1928986
Level 7
Level 7
First comment on blog 500 replies posted 250 replies posted

Hello.

There's a collection of projects at element14 website.
100 Projects in 100 Days - element14 Community
I think you're asking for something along the lines of Project #51.
PSoC 4 Pioneer Kit Community Project#051 – Music Player - element14 Community

You'll need to customize Project 51 to whatever hardware you have to work with.

Another is Project #57.
PSoC 4 Pioneer Kit Community Project#057 – Digital Audio From A Single Pin - element14 Community
Note: if the link doesn't take you to the project, google "element14 digital audio from a single pin" and click on that.

Good luck with your project.

0 Likes
lock attach
Attachments are accessible only for community members.

Attached is updated project #57. It uses 1-bit encription of the Super Mario theme using BTc SoundEncoder 3.0 by Roman Black. 

The BTc SoundEncoder 3.0 can no longer be downloaded from the original website www.RomanBlack.com, but it can be found here: http://www.talkbotbrain.com/.

The conversion tool produces *.C file, which is not directly compatible with GNU C for PSoC and need to be manually updated. I used simple Find/Replace ->Replace all option of the Microsoft Write. The Creator's built-in option didn't work, as Creator permanently hangs and had to be closed.

 

//original *.C file produced by the BTc Sound encoder
//-------------------------------------------------- 
void sound_data1()    org (1 * 256) 
{ 
   asm retlw 0x95 ; 
   asm retlw 0x55 ; 
   asm retlw 0x55 ; 
   asm retlw 0x55 ; 
   asm retlw 0x55 ; 
...

//manually corrected *.h file for PSoC
//-------------------------------------------------- 
const uint8 sound_data[] = 
{ 
   0x95,
   0x55,
   0x55,
   0x55,
   0x55,
...

 

 There are some additional erroneous lines, which had to be manually deleted using Find->Delete process:

 

// original *.c file produced by BTc SoundEncoder 3.0
...
   asm retlw 0xFA ; 
   asm retlw 0x50 ; 
   // reserved for MikroC return!  
   //------------------------------------- 
} 
 
 
 
//-------------------------------------------------- 
void sound_data2()    org (8 * 256) 
{ 
   asm retlw 0x0C ; 
   asm retlw 0x90 ; 
   asm retlw 0x14 ; 
...

// manually modified by deleting }...{ sections
...
   0xFA, 
   0x50, 
   // reserved for MikroC return! // <-can leave that  
   //------------------------------------- // <-can leave that 
   0x0C, 
   0x90, 
   0x14, 
...

 

 

Using CY8CKIT-042 PSoC4200 Pioneer Board (FLASH size is 32k) allows for about 10 sec of the continuous sound using 22.050kHz playback rate. Resources consumption is: FLASH 66.8% / 39.9%.

Using CY8CKIT-044 PSoC4200M Board (FLASH size is 128k) the resources consumption is: FLASH 16.9% / SRAM 10%.

It is clear, that using traditional 8-bit PCM sound encoding is practically out of picture for KIT-042, and will barely make a 1-second squeak. One may consider KIT-044 (128k FLASH) for PCM encoding of ~5sec playback.

/odissey1

PS attached are: 1. project archive, 2. BTc SoundEncoder 3.0 archive, 3. BTc SoundEncoder 3.0 Help, 4. Super Mario theme original WAV file (6-sec playback). 

 

Figure 1. Project schematic. Note that the RC values used by the Matt Landrum in his project differ from the recommended by the BTc SoundEncoder.

Sounds_01a_A.png

 

Figure 2. Screenshot of the BTc SoundEncoder 3.0.

BTcSE30BETA.png

John-M
Level 1
Level 1
First like given 10 sign-ins First reply posted

Thanks odissey1

Like the 1 bit example but realy need better sound quality. Ideally using I2S output, stream from a raw file.

Unfortunetly looks like for Project 51 all the design is in the two libraries SC Card and the encoder - will take a bit of unpicking to get htis working as I would like.

Yep, realy looking for I2S examples and maybe a DMA which can be added to the Psoc4 compoents library

Thanks

0 Likes

Can you specify the PSoC type you are using and sound duration needed?

I tested PCM audio with PSoC4200M, which has 128k FLASH, and at 22050Hz update rate all it can play is ~5sec long sound.

 

0 Likes

I drafted a test project demo playing the 8-bit PCM audio from FLASH using PSoC4200M and CY8CKIT-044 Pioneer Board.

PSoC4 8-bit PCM Audio Playback Using Interrupt 

Using this project one can check if duration and quality of the sound are satisfactory.

AudioPCM_signed_01b_A.pngAudioPCM_signed_01b_D1.png

 

 

I added another demo project playing 8-bit PCM audio from FLASH using DMA

PSoC4 Audio Playback using DMA 

 

 

AudioPCM_DMA_Schem.png

 

AudioPCM_DMA_D2.png

 

 

0 Likes

Thanks Odissey1,

Works like a dream on a CY8CKIT-044 Pioneer Board.

Thinks to note note is when building the audio file using Audiacity make sure you have selected the project to with the correct sampling frequency (Had me stumped for a while)

Currently looking at playing two sequences by reseting the pointer in the isrTimer handler (update IDAC output) -  not there yet as still brushing up on my C skills.

Cheers

0 Likes

For simple audio playback (without mixing the sounds) I recommend using DMA mechanism. You may check this extended version playing multiple sounds using DMA:

PSoC4 PCM audio playback using DMA (extended demo using two buttons)