Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.
Do you want it to sound like the London Philharmonic, or like a tacky birthday card? An FPGA can do both, although one of them is considerably easier.
Half of the fun of a project like this is dreaming up your own way of making it work. Start out by finding a song that has its note frequencies and durations listed in a table. Maybe put that table into a block RAM, and then step through the block RAM while feeding its data into a simple DDS frequency synthesizer and timer.
You have now applied high technology to making tacky birthday cards.
And for audio output, if you wish to have multiple-bits audio (ex: 8bit or 16bit audio) you can use multiple output lines to a DAC, or one or 2 single lines to a serial DAC, or even simple, no external DAC, by synthesizing a delta-sigma DAC (See XAPP154, applying it to Spartan-III).
I don't "program" in HDL. FPGA is hardware design. I visualize my project as a hardware block diagram. A counter here, a memory there, a couple of accumulators and multipliers here and there, a pinch of sequencing logic, etc. That's the fun creative part. Then I write HDL that implements those things. That's the drudgery part, because HDL was created by either a madman or a committee, I'm not sure which.
You can extract sample vectors for let's say a raw music file, like .wav, it will give you the raw samples of the music, you can use matlab or write a C code to do this. Then store this data on a memory, and design a circuit that will play this samples acording to a sampling frequency and stuff, you need a DAC, filters and so on.
Also you can make a simple synthesizer, to generate some waveforms using FPGA.
Then, when you 'play' your song, you have a counter that count to the first number and toggle flip-flop when the number is reached, and start again. For example, taking 11364, you'll have 11364 clock cycles with a '0' output, and 11364 cycles with a '1' output, over and over. Thus, you'll have a period that last 22728 clock cycles. With 10M clock cycles per seconds, this give a period of 22 728/10 000 000 = 0.0022728seconds (or by using '1/x', 439.9859Hz).
And the 2nd value of the table, count that many clock cycles before switching to the next entry.
Above, we assumed a '0' being a pause. If a 0 is read, simply do not output sound. Detecting the end of song, or song length, is up to you.
Of course, you can apply the above with any input clock frequency. You can have higher clock frequency, and divider, for higher precision, but this is often not necessary. To save space, you could encode the 2nd number (delay) as a lower value number, which is multiplied by a constant, to give the delay.
This will give a monophonic sound (one channel) square wave. With a piezzo buzzer, this will sound like a birthday card.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.