Arduino audio sampling tutorial (part 1)
Вставка
- Опубліковано 8 вер 2024
- This is a detailed tutorial how to play an audio sample stored in the program memory of the ATMega micro controller used by the Arduino mega 2560. It is also applicable to other Arduino types and stand alone AVR MCUs.
More Sophisticated solution will follow in the next part.
Used software:
Audacity - audacity.source...
bin2h alternative - bitluni.net/201...
Arduino IDE - arduino.cc/en/M...
the ending was great, wasn't expecting that!
barryg41 Bitluni at his best :)
I am learning so much. Like how he put in the delay of 62 microseconds to actually slow down the digital reading and thus analog writing of the file, to match the original sample rate. This guy is turning the mysterious into a simple nothing. He is teaching me the true speed of these micro controllers, how they can be used with audio data samples, etc. It is very enlightening. Thanks again BitLuni!!!!
For everyone that he has problem with bin2h..you do the following
Go to the link,then at downloads,download the exe file..put it in a folder with ur raw file then go to the command prompt go to your folder from the cmd(check a video tutorial how to change folder if u dont know)run the exe file from cmd and after write the bin2h filename.raw filename.h
Then at the folder that u have the file will find the .h file!
Yoohoo! It works! Thanks for planting that ear worm in my head. LOL Great video.
Woohoo it's works!! :D
So the line you wrote to tell the PORTC to send the 8 bits from the data() array, I believe you said that by placing the '&' symbol before the data reference, it becomes a pointer to the address in memory by making the reference '&' just before the array segment?
I'm trying to understand a little more about the Arduino, and I can't help but feel like I'm making things so much more difficult by trying to use that blasted IDE. They've just hurt me more with a new and improved release. But even by going over to ATMEL studio, it's environment is just as precarious, I'm not an EE, nor a programmer, but I wish I could be better at both without paying the dues.
Thank you for the super down to earth and patient presentation, and THANK YOU FOR YOUR CONTRIBUTIONS, here with your video, and elsewhere. I'm so glad there's good people like you, taking time to not only to point out the not so obvious to all, but also putting in work to help strengthen the weaker parts of the libraries and examples, and enhance them substantially.
Thank you for the video and for the r2r ladder instructions. All works great!
I had to add 'const' to the top line to compile this:
const unsigned char data[27123] PROGMEM =
Or perhaps, I did something wrong.
Ha ha ha, I wasn't expecting the ending.
The header file! That 8 bit(psuedo16 bit expression) sample as text was a great find here! Imagine the uses :) Thanks for posting.
Mình cũng thấy điều đó là hay nhất của video này!
Great tutorial :D Just finished it (used a speaker with integrated amplifier for simplicity :P) thank you very much!!!! :D
0:47 That's the problem with the uno. If the serial connection is used, it doesn't have a full 8 bit port.
Why all pins have to be from the same port? (I don't quite understand that) Thank you :)
Hi!
This is one of the best tutorials I ever have seen and the ending is hilarious awesome.
I will right away try to make the project just for fun and I will hope it WORKS to.
Thumb up for this one.
Have a nice time
thanks for the video.
One can safe some hardware and make it even simpler , if he uses the integrated Analog-Digital converter of the microchips.
There are tutorials available for this in the web, also for other processor-families.
I learnt new skill in programming.
Thanks a lot
If memory serves me correctly, you're using a DC coupled class A amplifier. I can't argue with success, but I probably would have added a capacitor between the final transistor and the speaker just to keep DC out of the speaker.
No, this is not class A amplifier. This is *common collector* (voltage follower) connection. The load (speaker) is connected between emitter and GND and the collector is common for both input and output stages. Darlington-like connection results with multiplication of beta factors (the equivalent transistor would have beta as product of beta factors of these two transistors). The common emitter configuration is here used for both *high input impedance* (not to put DAC under the load which would disturb its output) and for *high output current* (because the load impedance is just 4 Ohm).
Your videos are great, they are really easy to follow. Thank you so much for sharing.
I have a question: is there a way to change the tone of the sample? or must there be different samples for each tone?
Thank you very much for the video, plus instructive, very comical end
That "what abomination did i just create" face at the end, LOL.
You could do a simple OR to get closer to 62.5us. Something like 62 | (i & 1) could work.
Great video! Im having a bit of trouble with the Bin2H exe. It just opens up and closes imediatly after so im not able to use it. Has anyone else had similar problems or offer any suggestions?
Thanks again!
joe clarke
hey man just open your raw file by that bin2h
just right click on that raw file
and then open with
then select bin2h
and then you'll get your array
Breath work!!! Why did you send the signal to the base of the transistor and not to the collector??? I'm new to electronics and I've learned that a signal is transferred to the collector on the npn transistor.
Excellent video. What camera are you using? I'm very impressing with the focus adjust that you did.
wow... this video is quite old. it was a panasonic full hd handy cam. don't know the exact model anymore. the effect ist simple: zoom out while moving camera towards target. This changes the field of view
Thanks a lot, very beneficial informations. Now i have to find a way to tell arduino to read the samples from a tfcard reader
The end is the best part
Hello, I would like to suggest that you make STM32 project videos, specifically using each hardware module such as USB (Host / device), LCD etc. One model that can be more affordable to users and can offer a good deal of features is the STM32F407.
Hi Buddy, can you please make a simple audio controller like m-audio or focus rite than can plug in to FL studio to be use in auto tune. Thanks
what do you want to control in autotune? wouldnt a simple midi controller be enough?
my raw file from audacity didn't convert to a hex file, it converted it to some kind of a code format -128 to 127 instead of hex data?
me to, it work Right?
The link to downloading bin2h seems to be down. I also tried to download from other sites but it seems to not work for me when I execute it on CMD.
with a bit of modification to your code, i was able to stream nice audio through my serial port at 800000 baud 58KBs sample rate!
The cheapest solution! Good work!
great video indeed. very clear ..thumbs up & subscribed..thanks for sharing..Can you please teach us whether possible to add an SD card to extend the number of phrases, then call them case by case..like switch one says one, switch 2 says TWO..and so on ??
Muy bueno!!!! El final del vídeo grandioso también... Jajajaja saludos desde argentina!!!!
A budy of mine proposed that an arduino is "Real time" and the raspberry is not.
As of my last personal contact with the topic was that "real time processing" means performing a certain action takes a virtually fixed amount of time so you got a guaranteed processing time.
But I think for some reading over i2c the raspberry is fairly underwhelmed waiting on the slave since it is so much faster that the slight inconsistency does not necessarily hurt anyone.
What do you guys think on the topic?
Its easier to do with the Arduino framework.
However, a Raspberry Pi can also work in real-time. In most cases, unless your going for microsecond or even nanosecond timing, its more then enough usable with Raspbian.
Bare-metal programming (assembly or a optimal high-level language like C without a OS) or a optimal RTOS will suffice.
If a optimal real-time system was needed, i think that automotive-level microcontrollers, programmed in C using no dynamic memory allocation and multiple fail-safe mechanisms will perform much better and more reliably.
Excellent !
Thanks a lot for the upload. I've got a silly question : is there a way to connect an Arduino to an old computer with parallel or serial port ? I'd like to use the Arduino as an additional sound chip for retro computers : I'd load the samples I want to play in the Arduino, and there would be a program awaiting a signal to play a given sample, and the order to play would be emitted from the serial port or parallel port of the vintage computer. Would it work ? Can the Arduino read a signal from either an old serial or parallel port ?
Dat cinematography at the end, tho
its very Nice tutorial audio without SD, I made it, it works perfect but i want to play the loop once .... How to do that in coding Kindly help
You simply use a for loop?
OK.. Deutlicher Deutsch Akzent.. Schöne Demo und gut verfolgbar.(Frage was ist eine A zu A Wiederstands Leiter PINOUT zum nachbauen wäre nett) Die Darlington Schaltung mit dem große Transistor finde ich zu krass. (Wenn ich richtig liege hätte es auch mit dem BC547 geklappt nur hättest du zwischen Tr1 Emitter zu Tr2 Basis einfach einen 1KΩ Wiederstand auf GND verbinden müssen oder liege ich falsch??) Denke mal das es auch nen kleineren Transistor auf dem Board gegeben hätte. Bist halt auf Nummer sicher gegangen und hast den großen genommen.. Ergebnis klappt und gefällt mir auch. LIKE1... Für den Wiederverwertete Transistor gebe ich den 2ten LIKE.. Werde bei Gelegenheit das nachbauen und Programmieren und lasse dann noch mal nen Feedback von mir hören..
Good approach ! thx for the cue.
Hey great video. Can we use the same set up / system with a home theater system through a RCA cable?
Amazing .. Leant a new thing. Esp thanks for bin2h info !!
Hi ! I have also watched the part 2 and your video about ladder resistor making and I would know if it's possible to make a ladder with standard (bigger) resistors and whitch ohms'quantity for those ones is adapted to this type of sampler ?
=) Great fun, thanks for creating the video.
- Question, could this system use WAV files that are recordings of notes being played by a concertina (accordion), and play them back in response to buttons being pressed for each note in a scale? I'm hoping to create an electronic concertina. The note would have to sound instantly (less than, say, 100msec of delay).
- The standard MIDI voices aren't suitable. I have a .SF2 sound font file for the concertina. I think I can save each note as a .WAV.
- I have a MIDI controller built onto an Arduino UNO. It has a wire from each of the button switches, and outputs MIDI signals for standard MIDI, which is useful as well, but most important is to have the sound of a real concertina.
- Bruce Thomson in New Zealand.
If I understand correctly, the sample was 8 bit? Also, would it be possible to trigger the sample from a push button switch. And what about 16 bit 44.1 Khz samples? Is that possible on the Arduino?
DevinThomas That is possible. If you use 44.1 khz you will get a shorter recording time and if you use a similar setup you will probably not be able to hear the difference. To trigger the sample with a button just use something like: while(ButtonPin == 0){}
DevinThomas That is possible. If you use 44.1 khz you will get a shorter recording time and if you use a similar setup you will probably not be able to hear the difference. To trigger the sample with a button just use something like: while(ButtonPin == 0){}
Which is better ? This method of producing audio or the use of ESP32 DACs. And why?
Is it possible to use a PWM DAC instead of the R2- R resistor ladder? Thanks!
I was thinking of using the same circuit in the video, but taking the R-2R resistor ladder out of the circuit and just using the PWM output from my microcontroller.
Yes
To those who implemented this, can we replace the transistor by an Op-amp wired in voltage follower ?
Hello! What resistor values used at the ladder? I found this on Instructables, but I want drive my speaker with power mosfet.
www.instructables.com/file/FKGRU1UH74326MJ
Worth watching to the end for a sample of German humour :)
Can Arduino play more than one note at a time ? Looking for circuit and software for programming music. Tks.
can you plz specify the components with DETAIL that u had used in audio sampling
plz do reply
Bitluni is taking over the world one annoying circuit at a time! :)
Hi. Link to bib2h is already expired(( Can some one give me working version of bin2x?
thumbs up for the happy ending! :-)
Good video, but I have a question. can I add more than 8 bits pcm encoding and play the sound with the arduino mega?
can you please add a link in the description, pointing to the video you refer to as "last time" ? thanks a lot
great end!
Could you modify this to store sound in external EPROM or serial EEPROM / flash?
hello sir, can you help me to measure the distance by ultrasound and send a voice clip to the head phone via bluetooth.like if measures 20cm a voice will play to headphone " something ahead "...i need your help
Can you do this program with the input of a digital pin without a reset button?
If it is possible, please share with me
I dont think this is sampling. This is simply playing back a sample. Its not creating a sample as the video title implies :\
Exactly what I thought. It's somewhat misleading.
puru
I think the first step is to understand how to get the ADC running in what seems to be called 'free running mode'. I think over 40KHz can be sampled doing it that way.
Oh welllll
Tal cual xD
this is a scandal!! who could have guessed that this guy is a betrayer!! and he didnt even apologize...
Can you do this program with the input of a digital pin and play with this sound.
If it is possible, please share with me the helpful code.
i'm trying make an arduino 2560 was funny to find such video. you should have made an link to the last video, than i'll be even more thankfull for this video
i want to add this project a movement sensor so when i get in my room this must be play metallica music xD which tools i need? can someone help?
Do you have solution to 16kbit samples ? take a low adress and hi adress to output from 2 chanels ?
mega cant run pcm
library i change pwm from 11 to 10 it run incorrect cant control with the Arduino mega it crazy run
lol gold. All serious till the end.
i love you,... thanks
IT made my day laughing my guts out. hahaha great
When I run the bin2h.exe file, the CMD window pops up then closes by itself. I unblocked the program from windows but I'm still having this issue. Anyone know how I can fix this?
Do you run bin2h.exe through CMD? try copying both bin2h.exe and sample.raw to "C:\" (if c is your main Disk Drive) and then run cmd (e.g. for win7 open the start menu, write "cmd" in the search box and hit enter) after that exesute "cd .." several times until it gets you to "C:/>" and execute bin2h sample.raw sample.h
I have an issue with this. I tried the same thing as shown in your video, but the header file i obtain is not quite like yours. In fact, the Data array that your header file contains, has elements like "0xF7" or "0xE5" etc. My Data array on the other hand has elements such as "-114,91,-123,104," etc.
Is this a fault? or am i missing something?
please help me out
sir i got an array file from bin2h ,,, can you please help me how can I achieve same like storing it in program memory and produce sound by pwm but with pic microcontroller using micro c
Can I use this for "Arduino UNO"?
No, because of memory
Fuer raw to code sachen habe ich bisher immer Matlab genutzt - ist natuerlich nicht frei erhaeltlich. Leider gibt es bei manchen Compilern/Sprachen ein Limit fuer solchen Tabellen Code. Bei Java sind es 65 kB!
Did u get yout bait ball fishing system going? Trying to work out how to do similar
Hey, vielen Dank erst mal für das tolle Video! Leider bin ich bei meinem Projekt, bei dem ich mein Arduino Mega 2650-Klon nach Signal von einem Sensor auf die hier gezeigte Weise einen kurzen Audioclip ausgeben lassen will, vor ein Hindernis geraten:
Wenn ich deine Webapp nutze um meinen Audioclip konvertieren zu lassen, kommen teils negative Werte im Array raus, außerdem fehlt die Datengrößenangabe in den [eckigen Klammern]. Die Arduino IDE (1.6.12) beschwert sich beim kompilieren dann über jeden Wert mit den Worten "sorry, unimplemented: non-trivial designated initializers not supported." und wirft eine Fehlermeldung dass "storage size of 'myArray' is unknown'.
Hast du vielleicht einen Lösungsansatz? Ich bin Neuling und mit meinem Latein am Ende.
what is the number of thick transistor
Can this be done in a single pwm pin? i need to do that on my nano digital PIN 9
Could somebody step by step explaine how to get binar array from raw file?
Sir can I get the detailed explanation of your video arudino audio sampling video please
sir we have a project using an audio as an output.
sir if you don't mind please paste the schematic of this video.
Thank you sir
Im made it! Thanx...
sehr sehr sehr cooles Ende!
Love the ending. :)
VERY VERY NICE
what is the R value sufficient to out a speaker?
what kind of resistor is that
whats that array resister
The ohm rating of each resistor
Very informative video for the arduino teensy project I'm working on.
However I'm currently stuck on the part where he uses the bin2h application to create the header file.
The program just keeps writing the hex to the screen...:/
I've used similar utilities. Try something like this:
bin2h input.file > output.file
The "> output.file" part tells it to take what would have been written to the screen and saves it to the file instead.
***** thanks for that little tip :P, will give it a shot when I'm next using the facility
Hi Jo. I just tried the bin2h utility and it works really well. This is what I used:
bin2h.exe < input.file > output.file
There may be other methods, like pipelining but I didn't fiddle with that. The less than and greater than symbols can be read as "from" and "to".
The resistors are of which values?
amzing ending
How did you make the resistor ladder?
Hi, what is the resistor array resistance??
Is it possible to do with arduino uno?
8 bit r-2r ladder? Is it laser trimmed or what?
the "bin 2 h" on your site is gone.
It twerks!
Nice vid.
How much does it cost to produce one of these?
So, did it work?
wohooo, it works!
Nice, tolles Projekt :D Gibts auch einen Schaltplan davon?
no innocent electronics have been harmed...only the guilty ones
Can I have the software for programming?