FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Programs
(Moderators: fry, REAS)
   problems playing sound
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: problems playing sound  (Read 337 times)
rgovostes

rgovostes
problems playing sound
« on: Mar 27th, 2004, 5:58pm »

The following code should work fine - it loads up 12 sound files (one for each key on a standard TouchTone phone). Pressing a numerical key on your keyboard should play the corresponding DTMF tone, but after the first one there is lag between each successive sound. The sounds themselves have no delay at the end.
 
Perhaps this is a bug, but it looks like BSound stuff was removed from the Processing reference (though the files are still in the /reference directory of local copies, you cannot access them online or through the index.html file).
 
I originally tried to generate the tones myself, but I was having trouble with the tone sounding correctly, so I grabbed some .aiff files and converted them to .wavs (doubled the size, meh).
 
Code:
BSound[] tone = new BSound[12];
void setup() {
  // Load up sound files (8 KB each! yuck)
  tone[0]  = loadSound("0.wav");    tone[5]  = loadSound("5.wav");
  tone[1]  = loadSound("1.wav");    tone[6]  = loadSound("6.wav");
  tone[2]  = loadSound("2.wav");    tone[7]  = loadSound("7.wav");
  tone[3]  = loadSound("3.wav");    tone[8]  = loadSound("8.wav");
  tone[4]  = loadSound("4.wav");    tone[9]  = loadSound("9.wav");
  tone[10] = loadSound("star.wav"); tone[11] = loadSound("pound.wav");
}
 
void loop() {
  if(keyPressed) {
    if(key >= 48 && key <= 57) play(tone[key - 48]);
  }
}

 
Update: The delay was not as bad when running the applet through my web browser, but it still existed. So I thought I'd try with SONIA, which I haven't worked with before.
 
I got the original .aiff files again and resampled them to 16 bit. The sample rate is 22255 Hz and the sounds have one channel each. In QuickTime Player, I cannot tell the difference between the originals and the resampled files.
 
When I plug the following code into Processing and start it, it loads successfully and when I hit keys it even plays without delay. However, I hear static even when sound is not playing, and the sound files are distorted.
 
Code:
Sample[] tone = new Sample[12];
void setup() {
  Sonia.start(this, 22255); // Docs say this is kHz, it's Hz
  // Load up sound files (~8 KB each)
  tone[0]  = loadSample("0");    tone[5]  = loadSample("5");
  tone[1]  = loadSample("1");    tone[6]  = loadSample("6");
  tone[2]  = loadSample("2");    tone[7]  = loadSample("7");
  tone[3]  = loadSample("3");    tone[8]  = loadSample("8");
  tone[4]  = loadSample("4");    tone[9]  = loadSample("9");
  tone[10] = loadSample("star"); tone[11] = loadSample("pound");
}
 
void loop() {
  if(keyPressed) {
    if(key >= 48 && key <= 57) tone[key - 48].play();
    if(key == '*') tone[10].play();
    if(key == '#' || key == '=') tone[11].play();
  }
}
 
Sample loadSample(String name) {
  return new Sample(name + ".aif");
}

 
I can send the sound files to anyone who is interested.
« Last Edit: Mar 27th, 2004, 7:16pm by rgovostes »  
Processing

WWW Email
Re: problems playing sound
« Reply #1 on: Mar 27th, 2004, 8:20pm »

We've had alot of problems with the original Processing sound library and are no longer documenting it. I think we do need a Java 1.1 sound library, but the one currently in Processing is not robust enough. I recommend using Sonia.
 
+ Casey
« Last Edit: Mar 27th, 2004, 8:21pm by Processing »  
rgovostes

rgovostes
Re: problems playing sound
« Reply #2 on: Mar 27th, 2004, 10:30pm »

I wrote up an HTML example of what I'm doing, located <a href="http://rzg.macstorm.org/nifty/phone/">here</a>. It doesn't look right or even work in all browsers (Safari is the only browser I know it looks right in - but it doesn't work!).
 
Hold your phone up to your speaker and press the buttons to dial. With luck, it will work...
 
Pages: 1 

« Previous topic | Next topic »