Brazil
Offline
God Member
Karma: 1
Posts: 615
Wusik Dot Com
|
 |
« Reply #15 on: July 16, 2012, 04:57:43 pm » |
Ohhh, very nice! I need to download a library update, right? Thanks again for such hard work! 
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 6
Posts: 66
|
 |
« Reply #16 on: July 16, 2012, 05:02:41 pm » |
No, I have not changed the library yet. Maybe I will do it later after documenting it better - you only need the new batch file. We should try level-shifters or buffers (anything that is very cheap and easy available) to improve the sound (should be placed between Arduino outputs 9/10 and resistor stuff.
|
|
|
|
|
Logged
|
|
|
|
|
Brazil
Offline
God Member
Karma: 1
Posts: 615
Wusik Dot Com
|
 |
« Reply #17 on: July 16, 2012, 05:03:05 pm » |
I haven't messed out with the library source yet, but do you think it would be possible to get a more instant playback and re-play by setting an initial file, and just have it play, and re-play when requested? This way I could use this to playback long drum sounds. (crashes and cymbals) I need this for a small project I'm doing. ;-) Maybe an option to open the file and have it used until said to open a new one? Also, an option to re-start the file, even if its not done yet, for when you play a drum sound, you are in the middle, but needs to re-trigger the sound.
|
|
|
|
|
Logged
|
|
|
|
|
Brazil
Offline
God Member
Karma: 1
Posts: 615
Wusik Dot Com
|
 |
« Reply #18 on: July 18, 2012, 09:54:26 am » |
I wonder one thing, would it be possible to handle 16-bit stereo files? Using 4 x pwm outputs for 2 x 16-bit hybrid dacs? What's the limitation them? I see that a 5Mb SD Card can handle it without problems, is the bottle-neck the SPI or the ATmega itself? Maybe running at 20Mhz would help? Just wondering, as it would be KILLER to be able to play 16-bit stereo files.
|
|
|
|
|
Logged
|
|
|
|
|
Brazil
Offline
God Member
Karma: 1
Posts: 615
Wusik Dot Com
|
 |
« Reply #19 on: July 19, 2012, 08:50:26 am » |
In any event, it should be possible to handle mono 16-bit 31khz .WAV files now, right? I know how to handle WAV files, so I will see if I can be of any help on this...
|
|
|
|
|
Logged
|
|
|
|
|
Brazil
Offline
God Member
Karma: 1
Posts: 615
Wusik Dot Com
|
 |
« Reply #20 on: July 19, 2012, 12:34:04 pm » |
With this I got a perfect loop: while (1) { // Start playback SdPlay.play(); // Let the worker work until playback is finished while(!SdPlay.isStopped()) { SdPlay.worker(); } }
|
|
|
|
|
Logged
|
|
|
|
|
Brazil
Offline
God Member
Karma: 1
Posts: 615
Wusik Dot Com
|
 |
« Reply #21 on: July 19, 2012, 12:47:25 pm » |
I just tested the 16-bit hybrid dac with your code, as explained, and I love it, great quality!  I hear a strange buzz on the background, is that the PWM? I'm using an external power-adapter and running the ATmega328 at 3.3V, to keep the SD Card connections simpler. I haven't done your full 16-bit dac specs, I used a 256k and just one 1k resistor, so now I will try the way you did, to see if the buzz goes away. ;-) Thank you so much for the hard work on this lib!! 
|
|
|
|
|
Logged
|
|
|
|
|
Brazil
Offline
God Member
Karma: 1
Posts: 615
Wusik Dot Com
|
 |
« Reply #22 on: July 19, 2012, 12:48:44 pm » |
The project I'm working requires 4 loops to be played, not at the same time, but with the option to go from one to another. So I wonder if I could do some sort of pre-buffering for all 4 files, in a way I could just go from one to another with min. gaps?
|
|
|
|
|
Logged
|
|
|
|
|
Brazil
Offline
God Member
Karma: 1
Posts: 615
Wusik Dot Com
|
 |
« Reply #23 on: July 19, 2012, 01:59:43 pm » |
Ok, I found the buzz sound problem. It was the 3.3 V thingy. Now I'm running at 5V and using a proper SD Card adapter for Arduino (it has all the voltage converters) and it sounds GREAT! Thanks again! 
|
|
|
|
|
Logged
|
|
|
|
|
Brazil
Offline
God Member
Karma: 1
Posts: 615
Wusik Dot Com
|
 |
« Reply #24 on: July 19, 2012, 02:01:45 pm » |
Darn, the buzzing sound is still there, its from the PWM output. But its much lower now, compared to before.
|
|
|
|
|
Logged
|
|
|
|
|
Brazil
Offline
God Member
Karma: 1
Posts: 615
Wusik Dot Com
|
 |
« Reply #25 on: July 19, 2012, 02:41:26 pm » |
Ok, assuming you can also hear the buzzing sound there, how about using 2 timers? One for the DAC and another one for the sample-rate. For instance, Timer1, which you already use now for both sample-out and sample-buffering, you could leave just for the DAC and setup for 9 bits, so the frequency of PWM is much faster. Then another timer for the rest, lets say, Timer2. I will check the code when possible to see if I could just hack it and hear the result. At least on my 6-voice sampler I did it with a higher frequency PWM using Timer1 and there's no buzzing sound. Unless my chip is faulty. I will test my 6-voice sampler on this same setup, just in case. ;-) Here's the link: https://github.com/Beat707/BeatVoxAgain, thanks for doing this lib, I'm really loving it! 
|
|
|
|
|
Logged
|
|
|
|
|
Brazil
Offline
God Member
Karma: 1
Posts: 615
Wusik Dot Com
|
 |
« Reply #26 on: July 19, 2012, 02:59:58 pm » |
Darn, I can't figure out this buzzing sound, no idea where its coming from, maybe the SPI interface? (doubt that) What I see you did different from my 6-voice thingy, is that you take a bit to update the PWM outputs, I do it first-thing, from a 2-byte buffer, maybe that could help? I will try that. ;-)
|
|
|
|
|
Logged
|
|
|
|
|
Brazil
Offline
God Member
Karma: 1
Posts: 615
Wusik Dot Com
|
 |
« Reply #27 on: July 19, 2012, 03:36:19 pm » |
Darn thing, it does sound like the SPI. Here's a simple test. uint8_t bufferL = 80, bufferR = 80; void SdPlayClass::interrupt(void) { //SSDA_OC1L = bufferL; //SSDA_OC2L = bufferR; SSDA_OC1L = 255; SSDA_OC2L = 255;
uint8_t flags = _flags; // local copy for faster access ... void setup() { SdPlay.init(SSDA_MODE_HALFRATE | SSDA_MODE_STEREO); SdPlay.setFile("Loop5.a16"); // 16-bit mono file - half rate while (1) { SdPlay.play(); while(!SdPlay.isStopped()) { SdPlay.worker(); } pinMode(SCK, INPUT); digitalWrite(SCK, HIGH); delay(1000); pinMode(SCK, OUTPUT); } ... I can hear the buzzing sound, once the loop is done, it will pause for 1 second without the buzz sound. Unless I'm doing this test wrong. ;-)
|
|
|
|
|
Logged
|
|
|
|
|
Brazil
Offline
God Member
Karma: 1
Posts: 615
Wusik Dot Com
|
 |
« Reply #28 on: July 19, 2012, 04:11:28 pm » |
Well, it does seem to be the SPI clock leaking somewhere, not sure what to do... any ideas? 
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 6
Posts: 66
|
 |
« Reply #29 on: July 20, 2012, 10:07:43 am » |
Hi,
the buzzing sound can come from anything on the Arduino or stuff connected to it. I don't think that you can get rid of it just by optimizing the software - increasing sample rate will not change things. The quality out of the PWM is already superior, but get's damaged by the noise on the supply lines. Therefore as I proposed before try to use something that "isolates" the digital PWM lines from power source. Use a buffer or a level shifter. Then filter the supply for that level shifter very thouroughly using an own linear regulator or at least a serial resistor with a capacitor to gnd between VCC-digital and VCC-analog.
Regarding 4channel mode: If I translate the interrupt function to assembler then it should be possible to have enough computing power for stereo 16 bit playback...
Regarding pre-load: The function setFile stores internally something about the file in a small structure. By using that struct it should be possible to playback any file with very little latency. Maybe I will add this feature later to the library.
|
|
|
|
|
Logged
|
|
|
|
|
|