Arduino Forum

Using Arduino => Audio => Topic started by: Lucario448 on Feb 05, 2016, 05:38 am

Title: A bunch of questions about playback sampled sounds
Post by: Lucario448 on Feb 05, 2016, 05:38 am
Hi there! As the subject says, I want to playback a sampled sound without too much stuff.

First of all, I just have a Nano board with ATmega328P (aka V 3.0), and I don't have yet my SD card module; so I wrote all the samples of an almost 2 seconds sound, into the MCU's flash memory (my sketch barely fits into that).
Those are unsigned 8 bit samples, monaural audio and should be played at 16 kHz. So, in theory, I need a delay of aprox. 62 microseconds per sample. I guess everything is fine up to here; but now these are my questions:



I will really appreciate your answers and I hope most of you can understand my questions.


PD: this might be obvious. Since I can't use a SD card yet, then I can't use the TMRpcm library and play WAV files. Yeah, I'm doing this "the hard way", I guess...
Title: Re: A bunch of questions about playback sampled sounds
Post by: DVDdoug on Feb 05, 2016, 06:03 am
Quote
1.Since my board doesn't have a true DAC, can I use just a PWM pin to create sound (with a low-pass filter of course), or I should use the R-2R resistor ladder anyways?
The resistor should be MUCH better than PWM.   It's still not a proper DAC because it's not "clocked" and you might get audio glitches when the DAC value changes.


Quote
2.If I could use PWM, the analogWrite function may cause timing issues? (delays more than 62 microseconds) If yes, please tell me an alternative way to very quickly change the duty cycle.
It shouldn't cause "timing issues", but you'll hear the PWM frequency along with your audio.   Here (http://playground.arduino.cc/Main/TimerPWMCheatsheet) is some information about changing the PWM frequency.


Quote
3.If the R-2R ladder is my only option, could be a bad idea to override the RX pin as a digital output, by using the port manipulation?
I think it's a bad idea.  The Nano has 14 I/O pins and you only need 8 for the 8-bit resistor ladder.


Quote
4.Would you mind suggest me a good way to amplify the final output? Because I think that the output itself isn't powerful enough to drive a speaker.
You can use regular "powered" computer speakers, or you can plug-into your stereo system*, or get an amplifier.  Here (http://www.parts-express.com/lepai-lp-2020a-tripath-class-t-hi-fi-audio-mini-amplifier-with-power-supply--310-300) is an example of a small power amp.




* Be very careful "playing around" if you have a high-power stereo system...   You might get a loud glitch that blows your speaker, or you can end-up generating a high-power ultrasonic signal that you can't hear, but that's powerful enough to blow a tweeter or an amp.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 05, 2016, 08:38 pm
Quote
The resistor should be MUCH better than PWM.
No it is not. In theory it is the same but in practice it is much less due to the  tolerance on resistors.

Quote
Would you mind suggest me a good way to amplify the final output?
Any computer speaker or active speaker, these are very cheap.
Title: Re: A bunch of questions about playback sampled sounds
Post by: thomai on Feb 05, 2016, 09:02 pm
Look at this great tutorial: Arduino Audio Output (http://www.instructables.com/id/Arduino-Audio-Output/)

I build a 8-bit, 8 voice synth on an Mega2560 and it sounds great (I used the Timer3-Library to get the sampling right at 20kHz).

First I tried it without the op-amps, but you need at least one buffer circuit (=2 op amps), otherwise the output signal is distorted if you play bass and high frequency at the same time (which sounds great sometimes  :) ).

The audio output is connected to a hifi-amplifier. Small in-ear headphones will work but even small speakers need much more power (at least you can hear the hi-frequency/noise tones if you listen carefully...).
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 05, 2016, 10:26 pm
Quote
Look at this great tutorial: Arduino Audio Output
Sorry that is an absolute crap tutorial, and if you think it is great you have a lot to learn.
It does carray a warning sign to say it is crap, this is the word
Instructables
In the URL.

It is crap because you can not achieve monotonicity on 8 bits with an R-2R ladder with the tolerance of resistor that you can actually buy at anything other than an extortionate price. That author has not a clue what he is talking about, he just makes it above the level of the thickos who post comments.

On this forum we are getting fed up acting as tech support for poor instructable articles.
Title: Re: A bunch of questions about playback sampled sounds
Post by: AWOL on Feb 05, 2016, 10:27 pm
Quote
On this forum we are getting fed up acting as tech support for poor instructable articles.
Amen.
Title: Re: A bunch of questions about playback sampled sounds
Post by: thomai on Feb 06, 2016, 09:57 am
Having a bad day?

If you're quite new to electronics, imo this tutorial is the perfect way to start. It introduces all basic concepts and points in the right directions.

The kids who got their arduino at christmas may stop at the end of the page, but if you're really interested, this crappy little circuit is imo the best starting position for experimenting and digging deeper into each single concept.

Maybe in a commercial environment you'd use other circuits, but as a beginner you won't be able to understand them.

And what kind of audio quality do you expect when given a atmega328 with 8 bit resolution and 16kHz sample rate??? I expected almost nothing and it surprised me how far I can go with this simple setup.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 06, 2016, 11:56 am
Quote
Having a bad day?
Not until you showed up spouting rubbish no.

Quote
If you're quite new to electronics, imo this tutorial is the perfect way to start. It introduces all basic concepts and points in the right directions.
Just no on about every level you can think of. It does not point in any direction that is not a dead end.

Quote
Maybe in a commercial environment you'd use other circuits, but as a beginner you won't be able to understand them.
That is just rubbish.

The correct circuit is much easier to understand because:-
1) It is simpler.
2) The decisions you have to make in deciding what the circuit is are logical, rational and what is more you can carry the lessons learned onto other circuits.

The point is that knowledge is accumulative, you should be able to learn from one experience and apply that learning to others. To extend what you know.

It's like building a house, if you start off with crappy foundations then you might be able to build something a bit crappy as a first floor but anything greater will collapse.

Quote
And what kind of audio quality do you expect when given a atmega328 with 8 bit resolution and 16kHz sample rate?
A lot better than he achieved with that instructables.

Quote
I expected almost nothing and it surprised me how far I can go with this simple setup.
Well that shows you how much you know.

The setup could be simpler and the quality higher if he had done it right.
Take that buffer for example, can you explain why he uses that op amp when there are many that are better and cheaper. Can you also explain why he only uses one op amp in the package and so has to use two packages? Can you explain why he uses two batteries to power them?

What instructables are, are just some rank beginner who has cobbled something together with little or no understanding of what they have done. Then they say like a three year old "look at me". You do exactly what I have done and this will happen. That only works if they do "exactly" what he has done, which in most cases is not possible due to obscure components or inadequate design only working because all the tolerances went in his direction when he cobbled it up. Finally they are hyped up to appear to be ten times more than what they are.

In the mean time people think they have learned something, legitimately try and extend the project as proper learning would dictate, fall flat on their backsides, and come over here wanting help. We have to tell them all they thought they knew is wrong. They are sometimes reluctant to accept this and sometimes go away.

It is simpler to learn stuff that is right than to learn crap that is wrong.


The problem is that anyone can put one of these travesties up on line. There is no quality review or peer review at all. There are plenty of good stuff on line but you have to be able to sort it from the crap. Books on the other hand have some sort of minimum level of competency, but then you have to pay for that filter.
Title: Re: A bunch of questions about playback sampled sounds
Post by: thomai on Feb 06, 2016, 12:36 pm
Ok, I understand why you're upset. And thank you very much for your time explaining everything.

What kind of technique would you suggest?

This one here (http://interface.khm.de/index.php/lab/interfaces-advanced/arduino-dds-sinewave-generator/)?
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 06, 2016, 02:16 pm
Quote
What kind of technique would you suggest?
This one here?
That is one way of doing things, and is reasonable in its explanation. It will certainly deliver better results than the one you cited at first. The latest one you cited has a true 8 bit output and better restoration filter than most.

There are many ways to do this. The best way would be to use an proper A/D converter. Home made ones only work to about 5 to 6 bits and any more bits you add only add to the noise on the signal. Using a parallel A/D however is a poor decision because:-
1) The way the Arduino processor is made means you can't write 8 bits with one instruction, and writing in two or more instruction generates glitches in the signal unless there is a latch inside the A/D.
2) It simply takes up a lot of pins.
Using the 2R-R A/D ladder would be much better with only 5 bits and the pins used allocated intelligently so that the sample could be delivered in one direct port access instruction.

The best sort of A/D is one with a serial interface one, just a couple of pins and it is very quick send out data if you do it right. With the same interface you can have 8, 12 or more bits for the same number of interface pins.

There are two factors involved here, sample rate, how fast the samples are produced and quantisation rate, how many bits you have to specify a voltage. Both contribute to the noise and it is a bit of a balancing act as to what is best. The exact situation you are in contributes to that balancing act.

The limitations with an Arduino are mainly memory ones. You can generate signals like that last site you linked to, and you can generate any wave shape as well. For samples, like speech or music, without a source of external memory like an SD card you can only get about 3.5 seconds of audio. Which can be enough at times. I got a "yes" and "no" sample in only a quarter of the available memory.
Title: Re: A bunch of questions about playback sampled sounds
Post by: pjrc on Feb 07, 2016, 03:54 pm
It is crap because you can not achieve monotonicity on 8 bits with an R-2R ladder with the tolerance of resistor that you can actually buy at anything other than an extortionate price.
And even if you do pay the extortionate price, half of those super-accurate resistors are series with the on-resistance of the MOSFET transistors inside the chip.  The N-channel (for low) and P-channel (for high) are similar, but not perfectly matched in resistance.  Their resistance also changes considerably, so even if you manage to carefully measure the transistor effects and correct your external resistors for the particular chip you have, it'll only match well at the exact temperature where you measured.
Title: Re: A bunch of questions about playback sampled sounds
Post by: pjrc on Feb 07, 2016, 04:00 pm
The other huge problem with (simple) resistor ladders and also with PWM is the signal is directly derived from the power supply voltage.

Real DACs use a stable reference voltage, just like Arduino's ADC can use the internal reference, or an external one if you really care about an accurate reference.

When you use the power supply as a reference, any changes in the power supply voltage are reflected in the DAC analog output or ADC measured values.  For measuring pots, that's exactly what you want, since the power supply changes also change the voltage on the pot, so it using the power supply as a reference tends to cancel out those voltage changes.

But for a DAC, you'd almost never want to use the power supply as your reference voltage.  Any fluctuations or noise on the power supply go right into your analog signal.
Title: My reply
Post by: Lucario448 on Feb 08, 2016, 06:19 am
Whoa guys take it easy!!! I know you wanna help me, and I appreciate that; but please, calm down. Now I'm kind of confused.

Ok guys, I actually don't pretend to take this too far away (until I get my SD card module), for now I'm fine with the "simple stuff".

Now I have a problem. I tried to reproduce the sound with a PWM pin and a RC low-pass filter. Also I used a LM386-based amp to catch up the final output to a pair of earbuds (unfortunately I didn't have any PC speaker on hand). Apart from a lot of white noise, I just heard a PWM signal changing its duty cycle very quickly (before and after the filter), instead of the actual audio. What's wrong? Is not possible by PWM, or the low-pass filter isn't doing its job?

I'm gonna to describe my low-pass filter and tell me if something is wrong.

It's a RC low-pass filter. It uses 200 ohms for resistence, and 0.1 uF (100 nF) for capacitance. Resistor goes in series with the output, and the capacitor is connected; one node between the resistor and the output; and the other to ground (as a RC low-pass filter is supposed to be). With that values, in theory, I should achieve the "cut-off point" at aprox. 8 kHz.
For resistence, I used two 100 ohm resistor in series. And for capacitance, a small orange ceramic capacitor with a "104" printed on it.

Please tell me if I made something wrong. Also I'm gonna attach the source code file in case of something else.


PD: my apologies if my texts are a bit difficult to understand, that's because english is not my native language. And thanks by the way...
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 08, 2016, 06:43 am
I can't read a .ino file on an iPad why did you not just post it normally  using code tags.
Have you changed the default frequency of the PWM. It needs to go at least four times the sample rate.

That filter sounds wrong, the capacitor does not go on the output pin but the other end of the resistor to ground. Ceramic is a poor choice for audio work as it is not a very stable capacitance.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Lucario448 on Feb 08, 2016, 07:25 am
I can't read a .ino file on an iPad why did you not just post it normally  using code tags.
Oh, my bad. Code at the end of the replay.
Quote
Have you changed the default frequency of the PWM. It needs to go at least four times the sample rate.
How to do that? Is that "healthy" for the MCU? The change is permanent or just depends of the sketch itself? Will that affect the "delay" functions?
Quote
That filter sounds wrong, the capacitor does not go on the output pin but the other end of the resistor to ground. Ceramic is a poor choice for audio work as it is not a very stable capacitance.
Yeah. Another mistake of mine. When I said "output", I mean the output of the signal, not the actual output pin. And yes, one node after the resistors and the other to ground, as I said before. So, do you suggest me a electrolytic capacitor? A electrolytic one of 0.1 uF does actually exist?


And now here's the code (be aware that the samples' array were trimmed due to the character count limit of the post):
Code: [Select]
/*
 * This is the source code of a built-in-audio player.
 * At this way, it's attempting to reproduce a sound
 * with PWM.
 *
 * Made by Lucario448
 */

const unsigned char data[28167] PROGMEM =
/*
 * Never loaded into RAM, this very long array is read directly
 * from the flash memory.
 * I don't know if it could be a unsigned byte array, since
 * this is generated by program called bin2h.
 *
 * This array contains all the necessary samples to reproduce
 * the sound (displayed in hex form). Should be at a rate of 16 kHz.
 */
{
  0x7E, 0x7D, 0x7D, 0x7E, 0x7F
};
// The actual array were trimmed due to the character count limit of the post.
// The full array is within the file attached in the previous replay.


const int speaker = 9; // using pin 9 as the PWM output.
void setup() {
  pinMode(speaker, OUTPUT);
  // setting up the pin. I don't know if this step is redundant.

}

void loop() {
  // Currently not using a way to stop playing it unless by shutting-down the board.
  // So, this will keep looping the sound forever.
  for (short i; i < sizeof(data); i++) { // Scan throughout the array above
    analogWrite(speaker, pgm_read_byte(data[i]));
    // Assuming that this function takes a few CPU cycles to execute, maybe not true.
    delayMicroseconds(62);
    // If the comment above is true, then this delay should allow to playback the
    // samples at the desired 16 kHz.
  }
}
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 08, 2016, 02:28 pm
Quote
How to do that?
http://playground.arduino.cc/Code/PwmFrequency (http://playground.arduino.cc/Code/PwmFrequency)

Quote
Is that "healthy" for the MCU?
It has zero effect on the CPU, the CPU is not involved with producing PWM it is pure hardware.

Quote
The change is permanent or just depends of the sketch itself?
It will act until the next reset of the processor.

Quote
Will that affect the "delay" functions?
Only if you play with Timer 0, Using Timers 1 & 2 will not affect anything as the default option is to drive the PWM.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Lucario448 on Feb 08, 2016, 08:04 pm
Hey man. I changed the PWM to the fastest possible for pin 9. Still listening a PWM signal (and for some reason, I don't need amplifier anymore, for earbuds). Shall I need even a faster frequency (pin 3), or definitely the capacitor of my low-pass filter is not doing its job?

PD: I hope don't reduce drastically the life span of the flash memory, since the IDE overwrites all the same samples (29 KB) every time I need to upload any minimal change in the code.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 08, 2016, 09:23 pm
Quote
I changed the PWM to the fastest possible for pin 9.
No just set it to approximately four times your sample rate.

Quote
PD: I hope don't reduce drastically the life span of the flash memory, since the IDE overwrites all the same samples (29 KB) every time I need to upload any minimal change in the code.
Why should it? Any small change results in rewriting all bytes, it is the erase cycle that has a limit on them so it matters not if you change one byte or them all.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Lucario448 on Feb 09, 2016, 01:08 am
It's me once again hehe. Still listening a PWM signal (or whatever it is, but still not the actual sound).
So, it's definitely something wrong with the low-pass filter, or should I jump to the R-2R ladder and give up with PWM?

Look at my current code in case that there is the problem:

Code: [Select]
/*
   This is the source code of a built-in-audio player.
   At this way, it's attempting to reproduce a sound
   with PWM.

   Made by Lucario448
*/

const unsigned char data[28167] PROGMEM =
  /*
     Never loaded into RAM, this very long array is read directly
     from the flash memory.
     I don't know if it could be a unsigned byte array, since
     this is generated by program called bin2h.

     This array contains all the necessary samples to reproduce
     the sound (displayed in hex form). Should be at a rate of 16 kHz.
  */
{
  0x7E, 0x7D, 0x7D, 0x7E,
}; // Trimmed for the character count... blah blah blah.


const int speaker = 5; // using pin 5 as the PWM output.
void setup() {
  pinMode(speaker, OUTPUT);
  // setting up the pin. I don't know if this step is redundant.
  setPwmFrequency(speaker, 1);
  // Adjust the PWM frequency to the highest possible. Avoid using pins that mess up
  // the Timer0 (pins 3, 5, 6, or 11), otherwise "delay" functions may not work properly.
  // Temporarily using pin 5 since the maximum frequency possible is required.
}

void loop() {
  // Currently not using a way to stop playing it unless by shutting-down the board.
  // So, this will keep looping the sound forever.
  for (short i; i < sizeof(data); i++) { // Scan throughout the array above
    analogWrite(speaker, pgm_read_byte(data[i]));
    // Assuming that this function takes a few CPU cycles to execute, maybe not true.
    delay(40);
    // If the comment above is true, then this delay should allow to playback the
    // samples at the desired 16 kHz.
  }
}

void setPwmFrequency(int pin, int divisor) {
  // A function that modifies the PWM frequency of the specified pin.
  // Taken from http://playground.arduino.cc/Code/PwmFrequency
  byte mode;
  if (pin == 5 || pin == 6 || pin == 9 || pin == 10) {
    switch (divisor) {
      case 1: mode = 0x01; break;
      case 8: mode = 0x02; break;
      case 64: mode = 0x03; break;
      case 256: mode = 0x04; break;
      case 1024: mode = 0x05; break;
      default: return;
    }
    if (pin == 5 || pin == 6) {
      TCCR0B = TCCR0B & 0b11111000 | mode;
    } else {
      TCCR1B = TCCR1B & 0b11111000 | mode;
    }
  } else if (pin == 3 || pin == 11) {
    switch (divisor) {
      case 1: mode = 0x01; break;
      case 8: mode = 0x02; break;
      case 32: mode = 0x03; break;
      case 64: mode = 0x04; break;
      case 128: mode = 0x05; break;
      case 256: mode = 0x06; break;
      case 1024: mode = 0x7; break;
      default: return;
    }
    TCCR2B = TCCR2B & 0b11111000 | mode;
  }
}
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 09, 2016, 05:09 am
Is that the actual code you are using?

If so there is no sample in it.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Lucario448 on Feb 09, 2016, 06:32 am
Is that the actual code you are using?
Yes but...
Quote
If so there is no sample in it.
What does mean "samples" for you? The samples are all those bytes that recreate the analog signal. The "character" array stores the byte stream that recreates the sound (like a WAV file does). If you noticed, there are just four bytes despite of the array's size, that's because of the character count limit of the post that doesn't let me to copy-paste the whole array. The actual (complete) one is still on the sketch's file.
Is it absolutely necessary to post the whole array or what? Remember that it has 28167 bytes.
Title: Re: A bunch of questions about playback sampled sounds
Post by: thomai on Feb 09, 2016, 07:42 am
It's the delay. It waits 40 milliseconds.

You should call delayMicroseconds, which waits microseconds.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 09, 2016, 09:28 am
Glad you got it.
I was asking for the full code so I could try it and look on my oscilloscope what it was doing. I know it would be large but it could easily posted as an attachment.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Lucario448 on Feb 09, 2016, 03:48 pm
Ok man, here's the sketch's file with the full array of samples. I posted it as soon as I read your answer, because I will appreciate any help. I wanna feel the excitement when I could reproduce real sampled sounds with almost just an Arduino board!

The use of delay or delayMicroseconds are just for "trial and error" testing; specially if I messed up the timer 0...
Title: Re: A bunch of questions about playback sampled sounds
Post by: AWOL on Feb 09, 2016, 04:02 pm
Code: [Select]
    delayMicroseconds(3968);
252 Hz, absolute maximum.

Code: [Select]
for (short i; i < sizeof(data); i++)
You need to retake "For loop 101"
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 09, 2016, 05:08 pm
Thanks.
Attached is a sample of me saying 'Yes" at a sample rate of 8KHz.

Note in your code there is no need for:-
Code: [Select]
const unsigned char data[28167] PROGMEM =
just use
Code: [Select]
const unsigned char data[] PROGMEM =
saves a lot of counting.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Lucario448 on Feb 09, 2016, 07:54 pm
Code: [Select]
   delayMicroseconds(3968);
252 Hz, absolute maximum.
What if I messed up the Timer 0 and set it faster?
At default timer 0 speed, that value would be 62 instead of 3968 (62 * 64, because I think 64 is the default divider for the Timer 0 frequency)
Quote
Code: [Select]
for (short i; i < sizeof(data); i++)
You need to retake "For loop 101"
Uhhhh what does that mean? Is that an alternative way to itinerate through the samples' array?

Thanks.
Attached is a sample of me saying 'Yes" at a sample rate of 8KHz.
Done. But still no luck  :'(. So, will that be a filter problem, or I actually didn't change the PWM frequency all this time? (I don't have an oscilloscope to know it).


Quote
Note in your code there is no need for:-
Code: [Select]
const unsigned char data[28167] PROGMEM =
just use
Code: [Select]
const unsigned char data[] PROGMEM =
saves a lot of counting.
Thanks for your advice!  :)
Title: Re: A bunch of questions about playback sampled sounds
Post by: AWOL on Feb 09, 2016, 07:57 pm
Quote
Uhhhh what does that mean? Is that an alternative way to itinerate through the samples' array?
Plenty, but there is way to write a for loop correctly. (sp. "iterate")
Read it again.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Lucario448 on Feb 09, 2016, 10:10 pm
You need to retake "For loop 101"
How do I write that on my sketch? As it is or different?

And thanks for the misspelling correction by the way...

PD: still stuck with the audio output problem... :/
Title: Re: A bunch of questions about playback sampled sounds
Post by: AWOL on Feb 09, 2016, 10:12 pm
Check this (https://www.arduino.cc/en/Reference/For)
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 09, 2016, 11:01 pm
Quote
What if I messed up the Timer 0 and set it faster?
You should not be playing with Timer 0.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 09, 2016, 11:21 pm
Also in your code you have:-
Code: [Select]
delayMicroseconds(3968);
Assuming that is the only delay this means you are working on a sample rate of 252 Hz, I thought your samples were at 16KHz? It is no wonder you here nothing.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 10, 2016, 12:43 am
Basically the only thing right about that code was the setting of the PWM frequency.
You were using the wrong pin, I have changed it to pin 9.
You had the wrong delay value - I changed that.
You had the for loop wrong like AWOL tried to tell you.
But most of all you were reading the program memory incorrectly.

I think he is saying "my life for iera" although not ever watching films it means nothing to me.

Mended code attached.
Title: Finally solved!!!
Post by: Lucario448 on Feb 10, 2016, 04:11 am
Man... I'm so excited that I don't know how to thank you, for the patience, and all the help.
I CAN FINALLY LISTEN MY SOUND YAAAAAAAAAAY!!!

Basically the only thing right about that code was the setting of the PWM frequency.
You were using the wrong pin, I have changed it to pin 9.
You had the wrong delay value - I changed that.
You had the for loop wrong like AWOL tried to tell you.
But most of all you were reading the program memory incorrectly.


Quote
I think he is saying "my life for iera" although not ever watching films it means nothing to me.
Actually, my sound says "My life for Aiur!". It appears in a "old-school" PC game called "StarCraft".

And I think that's it. I'm satisfied right now.
In a future, I wanna do that but with a complete song, but first I need my SD card module of course.


PD:
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 10, 2016, 12:44 pm
Quote
So, isn't necessary at all to have a very fast PWM?
The faster the better but it needs to be at least twice as faster than the sample rate. As the sample rate is 16KHz that puts it at 32KHz. Having it faster makes it easier to filter out with a simple filter like you are using but as the PWM is way over the hearing frequency limit it is not so important. However such a strong out of band signal could screw up the electronics in the audio amplifier so it is best to leave it in. For the tests I just used a high impedance "ear bud" touched onto the pin directly.

Quote
The actual delayMicroseconds should be of 62, not 50
Only 62 if the for loop overhead, writing to the A/D, and fetching the sample byte from program memory takes zero time. I was trying it slightly shorter to compensate for these.

Quote
Exactly why? Because the variable i hasn't initialized from the beginning
Basically yes, also the short variable type, while part of C is not used much in this world.

Quote
It appears in a "old-school" PC game called "StarCraft".
Never had a PC so I wouldn't know.

Title: Re: A bunch of questions about playback sampled sounds
Post by: Lucario448 on Feb 10, 2016, 04:42 pm
However such a strong out of band signal could screw up the electronics in the audio amplifier so it is best to leave it in. For the tests I just used a high impedance "ear bud" touched onto the pin directly.
So my earbuds have lower impedance? Because I could barely hear my sound without using my LM386-based amplifier (which comes in handy because I can power it from the 5V pin of my board). Also, I think you mean for long periods of time, right? Using an amplifier for this purpose for a half of a minute doesn't destroy anything, or does it?

Quote
Only 62 if the for loop overhead, writing to the A/D, and fetching the sample byte from program memory takes zero time. I was trying it slightly shorter to compensate for these.
I noticed that the analogWrite function (plus the pgm_read_byte and the for testing condition) takes around 9 microseconds to execute (in a 16 MHz clock rate); thus at 62, the sound got a lower pitch than expected. In my "trial and error" testing, the value used to make it sound as it's supposed to, was 53 (and that's how I deducted how long takes that functions to execute, is that right or I'm wrong?)

Quote
Basically yes, also the short variable type, while part of C is not used much in this world.
So, for a "good programming practice", should I keep using int type variables for looping statements?

Quote
Never had a PC so I wouldn't know.
Well, now you know it haha.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 10, 2016, 05:40 pm
Quote
(and that's how I deducted how long takes that functions to execute, is that right or I'm wrong?
It is as good a technique as you can use in the circumstances. The delayMicroseconds call is only accurate to 4uS anyway so the technique is not very good for precise reproduction of a sample. For that you need to set another timer going (not timer 0 ) so that it generates an interrupt at exactly the sample frequency. Then the interrupt service routine does the fetches and loading of the PWM register. This means that you can do other stuff while the sample is playing, like LED animation or looking for a button press to set the sample going again. Like n.n.n.nineteen, that song from Paul Hardcastle.

Quote
So, for a "good programming practice", should I keep using int type variables for looping statements?
Yes if an int is big enough, you could use a byte, or a long, but always initialise the loop variable. It could start off with junk in it.

Quote
So my earbuds have lower impedance? Because I could barely hear my sound without using .....
Looks like it. These were the cheapest in a cheap shop I visited when I went to New York for the 2011 Maker fair, I don't have to put them in my ear to here the sound. ( Note I live in the UK so a visit to NY was a big deal for me )
Title: Re: A bunch of questions about playback sampled sounds
Post by: Lucario448 on Feb 10, 2016, 09:13 pm
For that you need to set another timer going (not timer 0 ) so that it generates an interrupt at exactly the sample frequency. Then the interrupt service routine does the fetches and loading of the PWM register. This means that you can do other stuff while the sample is playing, like LED animation or looking for a button press to set the sample going again. Like n.n.n.nineteen, that song from Paul Hardcastle.
So do you mean that the process of fetching a byte from the flash memory to the PWM register will not disrupt the sampling rate? Sweet! I wanna learn more about that, because it would be a useful knowledge for another project, like sensing the push of a button while playing an animation for a RGB LED strip (but not those that I can control each LED individually). Is that like simulating a multi-threaded (aka multi-task) process from a single-core CPU? 

Quote
Yes if an int is big enough, you could use a byte, or a long, but always initialise the loop variable. It could start off with junk in it.
Lesson learned!

Quote
Looks like it. These were the cheapest in a cheap shop I visited when I went to New York for the 2011 Maker fair, I don't have to put them in my ear to here the sound.
Are there one of those on Amazon, eBay or whatever? Or at least the brand and model name.
If that sensitive are those, I guess they can pick up the weak signal of a dynamic microphone without any sort of amplification.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 11, 2016, 11:33 am
Quote
Is that like simulating a multi-threaded (aka multi-task) process from a single-core CPU?
Yes that is called a state machine.

See my
http://www.thebox.myzen.co.uk/Tutorial/State_Machine.html (http://www.thebox.myzen.co.uk/Tutorial/State_Machine.html)
Or Robin2's several things at once
http://forum.arduino.cc/index.php?topic=223286.0 (http://forum.arduino.cc/index.php?topic=223286.0)

Quote
like sensing the push of a button while playing an animation for a RGB LED strip
Yes. Have you seen this project of mine?
http://youtu.be/pL0pMAPkkVw (http://youtu.be/pL0pMAPkkVw)
The animated face is made by sampling the envelope of the sound output and using the number to control what size mouth to display.

Quote
I guess they can pick up the weak signal of a dynamic microphone without any sort of amplification.
No I just tried it. I could barely see the signal when I whistle as loud as I can into the ear bud. It gives about 20mV. It says Panasonic on them but given the price and where I got it from it is almost certainly fake.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Lucario448 on Feb 12, 2016, 06:00 am
Yes that is called a state machine.
I got the point, but I'm confused in one thing. Why before you used the word "interrupt" if none of those tutorials used it?
They mostly used the millis function instead. So how that will improve the timing of my sound player?. Remember, the delay is in Microseconds, not milliseconds.

Quote
No I just tried it. I could barely see the signal when I whistle as loud as I can into the ear bud. It gives about 20mV. It says Panasonic on them but given the price and where I got it from it is almost certainly fake.
Ohhh that's a shame :/
If it is difficult to find one online, then would you mind if you suggest me an amplifier? (I know you already did it, but just keep reading)
I have in mind one that is small, easy to power-up, low consumption, stereo, cheap enough in case of unintentionally destroying it, and the most important: a lot less noisier than a LM386-based one.


Thanks beforehand!
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 12, 2016, 06:18 am
The reason you use an interrupt is so the task, which in this case is outputting the next sample, can be done at precisely the right moment. Because there is such a small interval between fetches then polling to see if the time is right is not only inefficient but does not give you fine enough control. The microseconds timer only gets updated every four microsecond for a start and then the other task or tasks in the Sate machine have to be completed in under the time between samples, which puts a lot of limitations on them. For example it means you can't do an analogRead while playing a sample without disturbing the timing.

By using an interrupt any other task gets suspended and your sample is changed on time. I would not say that non of the tutorials use this technique but as I said at the start of the thread there is a lot of crap out there. And an Instructables url is one way you can spot crap.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Lucario448 on Feb 12, 2016, 06:46 am
Correct me if I'm wrong. Do you mean that many mandatory functions inevitably consume a significant amount of time and it's impossible to achieve a 100% perfect timing? Well... at least is comprehensible that even delayMicroseconds is accurate enough, but not perfect (I guess due to clock rate).

Good tutorials though.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 12, 2016, 01:05 pm
Quote
Do you mean that many mandatory functions inevitably consume a significant amount of time and it's impossible to achieve a 100% perfect timing?
Yes. And that is with a task that contains only the one instruction, you will have to insure that all your tasks complete in significantly shorter time than the sample rate. Even then there will be a jitter of a time period equal to the length of your longest task. Using a delay is just a "baby" stop gap used as a demonstration or where you don't want to do anything else while a sound is playing.

Quote
at least is comprehensible that even delayMicroseconds is accurate enough
Any delay is blocking so your processor can not do anything else while it is waiting. A jitter of 4uS might not be noticeable at the low quality you have at the moment but it will soon show up as noise on your output. Remember 4uS equates to 64 clock cycles, about the same time as a digital write function call.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Lucario448 on Feb 13, 2016, 06:15 am
And that is with a task that contains only the one instruction, you will have to insure that all your tasks complete in significantly shorter time than the sample rate. Even then there will be a jitter of a time period equal to the length of your longest task.
Now I understand your point even better. You mean that I have a kind of "time budget" to do other things without compromising the sample rate, right?
If so, then I just have 53 microseconds to do other stuff (the time I'm "wasting" in a delay, in order to provide to the runtime a "time gap").
Is that enough time to do a AnalogRead and map functions? Because I wanna give to my current player a new feature: adjust the pitch (and speed along the way) with a potentiometer. Yeah, I had that crazy idea in my head since yesterday. It sounds like a something called "circuit bending"...

Quote
A jitter of 4uS might not be noticeable at the low quality you have at the moment but it will soon show up as noise on your output.
What kind of noise? A "waveform glitch" or something worse enough to blow off an amplifier?
Title: Re: A bunch of questions about playback sampled sounds
Post by: CrossRoads on Feb 13, 2016, 06:52 am
Standard analogRead() take 110uS.
Title: Re: A bunch of questions about playback sampled sounds
Post by: AWOL on Feb 13, 2016, 11:01 am
. . . but it's a very sImple function to take apart - most of the 110us is a busy wait.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 13, 2016, 02:52 pm
Quote
You mean that I have a kind of "time budget" to do other things without compromising the sample rate, right?
Right.

Quote
What kind of noise?
Time quantisation noise sometimes called sample noise. It is noise, that is signals that do not belong in there.

There are ways round the default analogRead, like to set the A/D in free running mode. But do it right and use interrupts, and let the other stuff that can wait, wait.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Lucario448 on Feb 14, 2016, 09:17 pm
There are ways round the default analogRead, like to set the A/D in free running mode. But do it right and use interrupts, and let the other stuff that can wait, wait.
How exactly can I do that? Do you mean that the "free running mode" will take less CPU cycles than AnalogRead function? But how can I retrieve the measures?

And what about the map function? How long it takes?
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 14, 2016, 10:06 pm
Quote
Do you mean that the "free running mode" will take less CPU cycles than AnalogRead function?
No. But it will not block your program while you are waiting for the conversion to compleate.
Quote
But how can I retrieve the measures?
From the analogue conversion register.

You can also make the conversion faster at the expense of a bit of precision:-
Code: [Select]

// set up fast ADC mode (Put in the setup function )
   ADCSRA = (ADCSRA & 0xf8) | 0x04; // set 16 times division


Quote
And what about the map function? How long it takes?
No idea, but it is only a bunch of arithmetic statements for those who can't remember kindergarten maths.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Lucario448 on Feb 15, 2016, 03:04 am
You can also make the conversion faster at the expense of a bit of precision:-
Code: [Select]

// set up fast ADC mode (Put in the setup function )
   ADCSRA = (ADCSRA & 0xf8) | 0x04; // set 16 times division

And which value should I put in it if I want just 8 bit precision, instead of the default 10 bit?
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 15, 2016, 10:56 am
There is noting that returns an 8 bit value, you just have to use the 8 most significant bits of the returned value. Shift right by two places is the way to do it.
>> is the shift right operator.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Lucario448 on Feb 15, 2016, 09:11 pm
you just have to use the 8 most significant bits of the returned value. Shift right by two places is the way to do it.
So do you mean that the ADC always return a 10 bit value?
If so, please explain me a bit more that line of code that sets the analog input pins in "fast mode", how to retrieve the data with this new configuration and how to discard the two bits.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 15, 2016, 09:33 pm
Quote
So do you mean that the ADC always return a 10 bit value?
Yes.
Quote
If so, please explain me a bit more that line of code that sets the analog input pins in "fast mode",
The A/D works with a clock that controls the timing, that line alters the pre scaler division ratio so that the clock runs faster and so the A/D runs faster.
For full information see section 23 of the ATmega328 data sheet.

Quote
how to retrieve the data with this new configuration and how to discard the two bits.
Exactly the same as before, with an analogRead function call. I told you about the shift operation to remove the lower two bits:-
Code: [Select]

eightBitValue = analogRead(0) >> 2;
Title: Re: A bunch of questions about playback sampled sounds
Post by: Lucario448 on Feb 18, 2016, 03:16 am
Is there a way to measure the time that a funcion takes to execute? (in clock "ticks"). Because, I don't know exactly how long the AnalogRead function takes in the "fast mode".

And I found a problem by discarding the two bits. For example: if the 10-bit value is 256, 512 or 768; discarding the two most significant bits will result in a 8-bit value of 0 (zero), in all those three cases.

I want to clear all my doubts before put anything in practice...
Title: Re: A bunch of questions about playback sampled sounds
Post by: AWOL on Feb 18, 2016, 08:24 am
Quote
And I found a problem by discarding the two bits. For example: if the 10-bit value is 256, 512 or 768; discarding the two most significant bits will result in a 8-bit value of 0 (zero), in all those three cases.
Why on Earth would you discard the most significant bits?
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 18, 2016, 08:41 am
Use the micros timer for timing function calls.

That code discards the two least significant bits not the most. Are you sure you understand what a shift operation is doing?
Title: Re: A bunch of questions about playback sampled sounds
Post by: Lucario448 on Feb 18, 2016, 09:11 pm
Use the micros timer for timing function calls.
Sorry for my ignorance, but how can I do that?
I mean, I want to execute a function, and then print the amount of ticks that the function took, to the serial monitor of course.

Quote
That code discards the two least significant bits not the most. Are you sure you understand what a shift operation is doing?
Whoops, my bad. You mean the LEAST significant bits, not the MOST ones. Very well, it works for me then...
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 18, 2016, 10:43 pm
You use micros to set a variable before you go into the routine.
https://www.arduino.cc/en/Reference/Micros (https://www.arduino.cc/en/Reference/Micros)

When you come out of it you subtract the current value from the one you stored to get how long it has taken.

Then you print out that number.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Lucario448 on Feb 19, 2016, 06:12 pm
What does mean "4 microseconds resolution"?

There is actually 4 microseconds between every micros count?
Or, the micros count has an accuracy of 4 microseconds? (+- 4 microseconds)
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 19, 2016, 07:20 pm
Quote
What does mean "4 microseconds resolution"?
It means that for any given number there may be a 4uS error + or -

Title: Re: A bunch of questions about playback sampled sounds
Post by: Lucario448 on Feb 22, 2016, 04:15 am
Hi. I tried to upload a sketch that tests the timing of all the functions I would need. I don't know why I can't even compile it. It throws an error telling me that the array variable (const actually) was not declared. Here's the code:

Code: [Select]
const unsigned byte array[9] PROGMEM = {200, 128, 255, 64, 7, 35, 50, 60, 215,};
unsigned long prevMicros = 0;
unsigned long currentMicros = 0;
unsigned long result = 0;


void setup() {
  Serial.begin(9600);
  Serial.println("Testing timing... (microseconds)");
  prevMicros = micros();
  pinMode(9, OUTPUT);
  currentMicros = micros();
  result = currentMicros - prevMicros;
  Serial.print("pinMode takes ");
  Serial.println(result);
 
  pinMode(13, OUTPUT);
  pinMode(2, INPUT);
 
  prevMicros = micros();
  digitalWrite(13, HIGH);
  currentMicros = micros();
  result = currentMicros - prevMicros;
  Serial.print("digitalWrite takes ");
  Serial.println(result);

  prevMicros = micros();
  digitalRead(2);
  currentMicros = micros();
  result = currentMicros - prevMicros;
  Serial.print("digitalRead takes ");
  Serial.println(result);

  prevMicros = micros();
  analogRead(A0);
  currentMicros = micros();
  result = currentMicros - prevMicros;
  Serial.print("analogRead takes ");
  Serial.println(result);

  prevMicros = micros();
  analogWrite(9, 128);
  currentMicros = micros();
  result = currentMicros - prevMicros;
  Serial.print("analogWrite (coded value) takes ");
  Serial.println(result);

  prevMicros = micros();
  analogWrite(9, pgm_read_byte(&array[2]));
  currentMicros = micros();
  result = currentMicros - prevMicros;
  Serial.print("analogWrite (fetched value) takes ");
  Serial.println(result);

  prevMicros = micros();
  Serial.print("Print this line takes ");
  currentMicros = micros();
  result = currentMicros - prevMicros;
  Serial.println(result);

  prevMicros = micros();
  map(512, 0, 1023, 0, 255);
  currentMicros = micros();
  result = currentMicros - prevMicros;
  Serial.print("map takes ");
  Serial.println(result);

  Serial.print("That's it...");
}

void loop() {
  // Nothing happens after setup function

}
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 22, 2016, 02:43 pm
That first line is wrong. You have a comma at the end and the declaration in the wrong order, it should be this:-
Code: [Select]
const PROGMEM byte array[9]  = {200, 128, 255, 64, 7, 35, 50, 60, 215};

This is what I got on Leonardo:-
Code: [Select]

Testing timing... (microseconds)
pinMode takes 8
digitalWrite takes 8
digitalRead takes 8
analogRead takes 208
analogWrite (coded value) takes 12
analogWrite (fetched value) takes 16
Print this line takes 40
map takes 56
That's it...

 
The case you are missing is when you do no operation, this base line overhead must be subtracted from all results for a meaningful measure.

Also due to the low resolution of the micros timer you should do more than one operation and divide the result by N where N is the number of times you did the operation.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Lucario448 on Feb 22, 2016, 06:19 pm
All right thank you for sharing your results. Now I know that the analogRead function is the slowest of all. Now I should test it but in the "fast mode"

The case you are missing is when you do no operation, this base line overhead must be subtracted from all results for a meaningful measure.

Also due to the low resolution of the micros timer you should do more than one operation and divide the result by N where N is the number of times you did the operation.
Ok then. So...
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 22, 2016, 06:35 pm
Quote
Do you suggest me to test even the micros function itself?
You do that when there is no function between the start and the end of the timing.

Quote
In order to test an operation mutiple times, which one of these statements will be faster: for or while?
The for will be the fastest but simply use copy and paste and repeat the single command then there is not any overhead for the loop. You can not use a blank loop to find the overhead because the compiler spots that and optimists it out of existence.

Quote
How can I test a substraction operation?
Taken care of in the blank, nothing to test - test.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 23, 2016, 03:34 am
What makes you think I am upset?
Title: Re: A bunch of questions about playback sampled sounds
Post by: Lucario448 on Feb 24, 2016, 07:56 pm
What makes you think I am upset?
Wait... WHAT? Are you worried because I'm taking longer to post a reply?

Well, whatever. Now I tested my sketch in my Nano board and these are the results:

Code: [Select]
Testing timing... (microseconds)
pinMode takes 8
digitalWrite takes 8
digitalRead takes 8
analogRead takes 208
analogWrite (coded value) takes 12
analogWrite (fetched value) takes 16
Print this line takes 22880
map takes 56
Now testing the analogRead function in its fast mode
Take note of the following 50 numbers!
Ready?
Set
GO!
16
20
20
20
20
20
20
20
20
16
16
16
16
16
16
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
That's it...

Notice that I added the "fast mode" of the analogRead function, and tested it 50 times. The average of all that values is 19.44. In conclusion, the analogRead function in "fast mode" takes around 19 and 20 microseconds. Can it be considered correct?
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 25, 2016, 08:24 am
Sorry some one posted that I sounded upset. Now they have removed the post so it sounds like I was talking to you.

Yes 20uS sounds about right.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Lucario448 on Feb 25, 2016, 07:41 pm
Sorry some one posted that I sounded upset. Now they have removed the post so it sounds like I was talking to you.
Haha, roger that!


Now, on the other side; is there a disadvantage of setting up the analogRead in the so called "fast mode"? Accuracy loss or what else?
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 25, 2016, 11:10 pm
It is going to be a bit nosier the faster it goes but with just speeding it up that much it should be OK. The thing is you are not switching between analogue channels and that is what takes the time. Letting the signal stabilise after the switch.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Lucario448 on Feb 26, 2016, 08:15 pm
It is going to be a bit nosier the faster it goes but with just speeding it up that much it should be OK. The thing is you are not switching between analogue channels and that is what takes the time. Letting the signal stabilise after the switch.
So what actually makes it faster? By ignoring the other inputs or skipping the "stabilization time"?


Hey... and by the way, I want to take this even further. I'm going to try to produce stereo audio; but first, clear my doubts:



Ok, that's all I need to know. Now I'm going to create the sound for testing, and also spoil you what it will be.
It will be a 1 kHz sine wave that goes throughout the channels! (around and around if looped)
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 26, 2016, 10:25 pm
Quote
Due to small memory, I must cut down the sampling rate to 8 KHz, but shall I keep treating the sound as if it has a 16 KHz sampling rate?
No if it is sampled at 8KHz then treat it as 8KHz.

Quote
So what actually makes it faster?
Speeding up the clock that drives the successive approximation A/D. It means it spends less time on each bit's decision.

Quote
Correct me if I'm wrong. Digital stereo audio stores its samples by alternating all its channels. For instance: if the data is stored in an array, then the even-numbered indexes correspond to the samples of the left channel, and the odd-numbered indexes correspond to the samples of the right channel.
While that could be used it is not the way it is normally done. There is a separate buffer for each channel and it is possible that one channel compresses more than the other. If they are interleaved like this then you can't apply any compression later on.

Quote
By using analogWrite twice per loop (in order to update the duty cycle of both channels), will this create a sort of "phase shift" to the right channel? (if the left one is updated first)
No because the analogue write update does not happen immediately but only when the clock gets to a transition. As this time change is way above the filter's cut off frequency then in effect there is no phase shift.
Title: Re: A bunch of questions about playback sampled sounds
Post by: Lucario448 on Feb 27, 2016, 07:55 pm
There is a separate buffer for each channel and it is possible that one channel compresses more than the other. If they are interleaved like this then you can't apply any compression later on.
The samples are in the uncompressed form (thus the sampling rate decrease), so am I ok?. I think that's how a WAV file stores the samples of a stereo sound...
Title: Re: A bunch of questions about playback sampled sounds
Post by: Grumpy_Mike on Feb 28, 2016, 12:00 am
Quote
The samples are in the uncompressed form
Yes I know, what I said is that you can't apply compression to the whole file.

Sure if you deal with everything in an interleaved format you can do that, but it is not what is normally done.