element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Cypress Kits
  • Products
  • Dev Tools
  • Cypress Kits
  • More
  • Cancel
Cypress Kits
Forum PSoC 4 Pioneer Kit Community Project#057 – Digital Audio From A Single Pin
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Cypress Kits to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 10 replies
  • Subscribers 27 subscribers
  • Views 1647 views
  • Users 0 members are here
Related

PSoC 4 Pioneer Kit Community Project#057 – Digital Audio From A Single Pin

cy.wbz
cy.wbz over 12 years ago

Hello!

 

In this example we will show you how to use a digital signal to generate analog sound effects using the PSoC 4 device. The example projects will encode a sound as a string of 1s and 0s which, when smoothed by an RC filter, creates an approximation of the original sound.

 

image

 

Please refer to the following web site that explains the concept and algorithm in detail. This example was adapted from this web page.

We have included an example of the 1-bit audio output at the bottom of this post.

 

Forum Post Attachments:

 

At the bottom of this post we are including the following items:

  • Example Project Zip File
  • Zip File of Images
    • Project Schematic
    • Component Configurations
  • Audio Recording

 

Components Used:

 

The user can download the example project at the bottom of this post. The project uses the following list of Creator Components:

  • SPI
  • CyClock
  • CyPin

 

The components are configured by right clicking on the component in your Top Design schematic view and selecting Configure. Please enable the following selections in the Configuration windows for the listed components above.

 

Firmware Description:

 

The main.c firmware is included in the example project. Please review the commented sections for more details.

 

At a high level the following actions were taken with the example project:

  • Convert a sound effect .wav file to 1-bit sound format (encoding the data)
  • Convert the 1-bit format to an array of bytes (formatting the data)
  • Shift out the array to a pin connected to a speaker (playing the data)

 

Encoding the Data:

 

The sound effect .wav file was converted to 1-bit format byte array using the free BTc Sound Encoder 3.0 software developed by Roman Black.

 

image

 

There are some important features to this software:

  • Being able to resample the data at a different rate
  • Simulating what the 1-bit sound would sound like
  • Seeing how the 1-bit sound wave matches the actual sound wave
  • Exporting the 1-bit format data to a ‘PIC Mikro C file’.

 

image

 

Formatting the Data:

 

The generated code from the above application is not directly readable by the PSoC. It needs to be converted to an array of bytes to allow for the array to be initialized when declared. This step was done using a Python script (attached to this post).

 

image

 

Playing the Data:

 

Once the sound is ready to be initialized as an array in C, playing it out with the PSoC is simple. In the example we use the SPI component to output the values to the RC circuit. The array of data is shifted out MSB first using the SPIM Component.

  • Since the data was sampled at 11.025 kHz, the SPIM is clocked at 22.050 kHz to achieve a bit-rate of 11.025 kHz.
  • Playing around with the (external) passives did not have much of an effect on playback quality. Playback quality is primarily determined by the bit-rate and is a tradeoff with the flash footprint.
  • The flash footprint of the projectwith 5 sound effects (bark, bell, boing, quack, crowing) is ~9k.

 

Hardware Connections:

 

In this example the user will need to connect an external RC circuit to an external speaker. The SPIM component is then connected to Pin 0[4].

 


image

 

Test Your Project:

 

Program the Pioneer board and enjoy the sound effects.

 

I hope this example can help you in your design.

 

Best,

Matt

Attachments:
Audio Example.m4a
Sounds.cydsn.zip
2625.Project Images.zip
  • Sign in to reply
  • Cancel

Top Replies

  • Former Member
    Former Member over 12 years ago +1
    Hey, A few things to note: 1. Thanks to Roman Black - the author of the BTc software. He has been around for a long time, and kudos to him for doing such a good job at this software: http://www.romanblack…
  • Former Member
    Former Member over 12 years ago

    Hey,

     

    A few things to note:

    1. Thanks to Roman Black - the author of the BTc software. He has been around for a long time, and kudos to him for doing such a good job at this software: http://www.romanblack.com/picsound.htm

    2. The first sound in the attachment is a robotic voice saying: "I sound like a 1980s movie computer"

    3. Don't let the SPI throw you off - it is being used as a shift register to shift out the sound. A 8-bit shifter register with a 3-bit counter (for shifting out 8 values) would have sufficed. The current implementation just was easier.

    4. To get better results, buffer the pin output using PSoC 4's opamp, before sending it to the speaker. You will notice that the resultant waveform at the speaker (seen on an oscilloscope) is much more like the screenshots above.

    5. The sound quality is in a large way determined by the bitrate and size of the audio samples.

     

    Listen to the audio file, try it out, and let me know what you think!

     

    With a little more effort, the sound quality can be made good enough for simple toys or such applications.

     

    Have fun!

    Antonio

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • DAB
    DAB over 12 years ago in reply to Former Member

    Hi Antonio,

     

    Thanks for the link and references.

    I agree, the idea is very simple.  You just control the charge on the capacitor using time spacing between the bits.

    I think you could improve both clarity and reduce artifacts if you used two or three shift registers in conjunction with an adjustable waveform mixing circuit.

     

    Definitately a neat idea for sound effects.

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 12 years ago in reply to DAB

    Hey DAB,

    Thanks for the idea, and for the different way of thinking about the project.

    Such projects really help revisit fundamentals and understand every-day science in a slightly different way

    Best.

    Antonio

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • jesusantoniocar
    jesusantoniocar over 12 years ago

    Hello Matt, Antonio.

    Another great project.

     

    best regards,

     

     

    Jesus Antonio and Juan Jose.

    You don't have permission to edit metadata of this video.
    Edit media
    x
    image
    Upload Preview
    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 12 years ago in reply to jesusantoniocar

    Wooh!

    Nice job, guys.

     

    In case you need to, do try to get your own sounds into the PSoC, and let me know if you have questions.

     

    The entire process of using the BTc software yourself, converting the wav file into an array, and hearing it on the PSoC generates quite some learning.

     

    You could even record your voice using a software like audacity (http://audacity.sourceforge.net/) (it's an AWESOME piece of sound-editing software) and play it out on the PSoC.

     

    Enjoy yourselves!

    Antonio

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • DAB
    DAB over 12 years ago in reply to jesusantoniocar

    Hi Jesus and Juan,

     

    Very entertaining.  I like that you involved your son in the build.  Hook them on technology when they are young and they will be fascinated with it for a lifetime.

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • DAB
    DAB over 12 years ago in reply to Former Member

    Hi Antonio,

     

    I agree, Audacity is an awesome piece of free software.

    I use it in my lightning research.  I can collect the data using various sample rates and I can then analyze the recorded audio signals.

     

    It works very well.  I have not done much with voice or music processing, but it appears to have all of the tools you need.

     

    So I encourage everyone to download Audacity. 

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • jesusantoniocar
    jesusantoniocar over 12 years ago in reply to DAB

    Hello DAB.

    Thanks for your reply.

    my son is 7 years of age, really enjoys technology, Handles my smarphone better than me and of course fascinated psoc experiments.

     

    Best regards,

     

    Jesus Antonio.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 11 years ago in reply to Former Member

    Hey,

    Well I download the project and got it working with the default sounds.  I tried running BTc.exe to create a different bit scream.  The problem is I am running window 7 and the download site is saying XP or maybe vista.  I cannot open a wav file. Has anyone tried to run this in Window 7 or even 8.1?  I tried several different wav files.  I get the following Msg:

     

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 10 years ago in reply to Former Member

    Ill try it out sometime soon and let you know, Brian

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube