How to play audio file from verilog simulation? - verilog

My objective is to have a verilog module with an input (from a DE2 board like a clock or key) that triggers an audio file to play. How can I accomplish this using Quartus and a DE2 board?

Just start with a blinking LED.
As second you can try a running light.
Lesson tree is start to make noise with your FPGA.
And now you can start to send samples from a memory to your speaker.
Don't forget: Simulate first, synthesize second!

Related

play audio with pwm of a attiny85

I'm trying to understand how to implement audio playback from scratch on attiny85. The goal is to play a short sound (cat meows, so i want it to remain recognizable) from an array representing strength of audio signal sampled at fixed interval.
As far as i understand, signal strength is linearly mapped to voltage of analogue audio signal. As far as I know, audio cards are Digital to Analogue Converters, but attiny85 probably doesn't have that.
I'm curious if I can use pwm to play the sound back. Since pwm changes average voltage by changing duty cycle of alternating high and low phases of signal, it most likely would result in the drop of audio quality. Wav sampling rates can differ between 1 HZ and 4.3 GHz according to google. Attiny85 has internal clock with frequency up to 8MHz (which I hope is same for it's pwm generator).
Considering reconfiguring the timer and pwm settings as well as looping in the array, what is the maximum sampling rate of audio i can reliably play? And should i even try to do it with pwm, or there are better options?
Given a system clock of 8 MHz, you can use PWM to generate mono (single-channel) audio.
Consider a PWM period of 1000 clocks, giving you about 10 bit resolution. The sample rate will be 8000 Hz then, which gives you some kind of lo-fi audio.
If you reduce your signal resolution to 8 bits, you'll get 8 MHz / 28 = 31.25 kHz sample rate. This gets near hi-fi.
Synchronize your sample output with the PWM generator, and use an appropriate analogue filter.
Many years ago I built a digital door bell with a sample rate of 8 kHz and 8 bit samples. It played nice sounds in the quality of telephones. The microcontroller was a 8051 derivative and it used an R-2R ladder as DAC.
A simpel sinus can be generated by using a 50% PWM signal and varying the frequency. Given some filtering effect through the speaker, it would mimik a single tone audio signal.
Making more advanced tones (needed for natural sound) quickly gets more complicated and the duty cycle of the signal can also be used to trick the human ear into hearing harmonics. Check out the arduino function tone() for some inspiration.
Be carefull when connecting a small speaker to the Arduino, preferably a transistor/buffer/small amplifyer should be place between the Arduino and the speaker.

Using nidaqmx to trigger signal in line with behavioural task

I am using the python nidaqmx API to instruct a USB-6009 DAQ to output an analog signal when a tone plays. I am trying to use the API guidelines and also the previous stackoverflow question (Triggering an output task with NIDAQmx) but still need help.
The timing of the tone is set using Psychopy, a python-based behavioural task package.
The general format of this would be:
if tone = on:
trigger_digital_output
I just cannot figure out the code from the nidaqmx documentation to trigger the analog output. Additionally, will I need to specify a digital input (USB-6009 will be connected by USb to my computer).
Thankyou
According to its specifications, the USB-6009 does not have any hardware triggers for analog output, and only a digital edge trigger for analog input.
So for your analog output task, you would use the same approach as the topic you referenced: use stop() and start() to begin the output each time you want to generate it.
The Digital I/O on the USB-6009 is only software-timed: the input or output happens on-demand, each time you call the read_one_sample_one_line() or write_one_sample_one_line() functions.
To get started with the full DAQ commands, there are a few Python examples on GitHub
analog output
digital output
digital input

Active Noise Cancellation - feasibility

I'm planning a micro-controller project on active noise cancellation.
The idea is:
Speaker_1 generates 100-200 Hz noise (constant frequency).
Microphone records Speaker_1.
Signal is passed into micro-controller for DSP.
Output from micro-controller is 180 degree phase shift of input.
Output signal goes to Speaker_2.
Sound from Speaker_2 cancels sound from Speaker_1. Room is silent
My questions are:
Is this idea feasible? (I saw demo here: https://www.youtube.com/watch?v=UyN1TACCbHE)
Once the noise-cancellation does start to work, then wouldn't the microphone receive no input? Thus no signal equates to no noise cancellation?
Before you waste too much of your time try this: Take two speakers. Reverse the speaker wires on one to switch the phase. Now play a mono signal through them. You'll find pretty quickly that the room is not silent. There will be some cancellations at some frequencies but that will be highly dependent upon your listening position and the speaker locations.

How to get absolute signal in PyAudio?

I'm trying to use pyaudio to analyze audio playing on my computer's system. To do this I am selecting a recording device called Stereo Mix as my input signal into pyaudio. Stereo Mix seems to be a recording device provided by my computer's soundcard, VIA High Definition Audio.
The problem is the signal I get from pyaudio changes in amplitude when I increase the volume on my computer. I would like to get an absolute signal which does not change with increased volume (ideally the raw signal generated from the computer's system). Does anyone have a solution this problem?
Thanks

Recording wav file Using Arduino

I am bit stuck, how can I make my arduino record into .wav files?
The arduino is connected with a microphone, and am using the Arduino ADC.
Any ideas? Will I be able to play them back using my pc?
many question cross my head
1- Is this possible using an arduino Uno
2- Is this possile using just a microphone connected to the Arduino ADC
3- if yes how can i get the wav format.
The idea gonna be like this
Ardiuno microphone-->Uno ADC -->arduino (library making wav sound)--> Storing data to a an SD card connected via SPI or maybe (connecting a Raspberry as a storage device)
also another question:
4- Do I need an amplifier due to the act that analog output from the microphone is very weak so the ADC couldn't detect the variation
In another log i had seen that i should connect the microphone to a level shifter.And that cause of the analog output is AC so i have to make the negative wave as 0 (for 10 it ADC)
the zero point as 512 and the positive as 1024 (10 bit ADC).(really i'm not sure about this part)
doing some research i got this library "https://github.com/TMRh20/TMRpcm/wiki/Advanced-Features#recording-audio" which is supposed to do the job, I mean making some wav file from the analog input.
So any help would be appreciated
Thx in advance,
Salah Laaroussi
Yes, although a bit complex it is very possible to do this via an uno.
The biggest hurdles to overcome is the limited amount of RAM and the clock speed. You will have to setup twin buffers to handle writing to the SD card. Make sure the card has a high enough write speed or the entire program will come to a screeching halt as you will run out of memory.
apc mag has a great article detailing out the circuit and code.
http://apcmag.com/arduino-projects-digital-audio-recorder.htm/
There are many things you haven't prepared yet:
output of microphone (assuming you know about electronics: still requires a biasing circuit e.g. a resistor + capacitor).
the output of the microphone is still very weak (in the magnitude of mV), which Arduino is incapable of capturing so you need a pre-amplifier
the design of the pre-amplifier will also include DC offset which makes the output of the microphone all above 0VDC which is in the range of the Arduino ADC otherwise the arduino will capture only those above 0VDC.

Resources