Processing Audio Data

Everything todo with programming goes HERE.
Post Reply
User avatar
sinewav
Graphic Artist
Posts: 6497
Joined: Wed Jan 23, 2008 3:37 am
Contact:

Processing Audio Data

Post by sinewav »

I have an idea for a small, simple program, but the only languages I even barely know are Java amd PHP. From what I've read so far, getting audio to work in Java seems like rigamarole. After several hours I haven't found any examples on the web that describe the process, and even found info on Oracle's website that suggest it might not even be possible. I even went to the bookstore to find the answer. Only one book out of six had a section dedicated to sound, and it was two pages long. The book was over 700 pages. Needless to say, the two pages of information about sound didn't cover my needs. I mean, all I want to do is play a sample randomly at different pitches.

Anyone have experience with OpenAL? I think PHP can use that or something.

Anyway... I don't know where to turn. I guess I'm ready to dive in and start learning another language, but which? I'm not too bright when it comes to this stuff.
User avatar
nsh22
Round Winner
Posts: 378
Joined: Fri Sep 07, 2007 8:12 pm
Location: eating, cooking or writing (about cooking).
Contact:

Re: Processing Audio Data

Post by nsh22 »

Lucifer wrote:I think you got the wrong thread, this thread is the one where we're debating banning sinewav and dubStep until they have a threesome with dubbie's mother.
User avatar
Light
Reverse Outside Corner Grinder
Posts: 1667
Joined: Thu Oct 20, 2011 2:11 pm

Re: Processing Audio Data

Post by Light »

You can play WAV files in Java, but I ain't sure about MP3's 'n such. PHP would be a poor choice as it would have to trigger another application to do it as PHP is server-side scripting. You're not meant to interact with it.

It comes down to what you're wanting to use this program for and/or with. In a browser, you can use html, javascript, flash, etc.
User avatar
Lucifer
Project Developer
Posts: 8756
Joined: Sun Aug 15, 2004 3:32 pm
Location: Republic of Texas

Re: Processing Audio Data

Post by Lucifer »

Well, to start, find an audio library with java bindings, if you know enough java to do it. So, google "java open source sound library" and see what you get.

If that doesn't work, go with python. :) Python's fairly straightforward, and there are several audio libraries available for it.

The thing you're not doing right is looking for the language to support it. In fact, no language directly supports hardware access, but there are numerous libraries available for every language. So you just need to find a library for *your* language.
Check out my YouTube channel: https://youtube.com/@davefancella?si=H--oCK3k_dQ1laDN

Be the devil's own, Lucifer's my name.
- Iron Maiden
User avatar
sinewav
Graphic Artist
Posts: 6497
Joined: Wed Jan 23, 2008 3:37 am
Contact:

Re: Processing Audio Data

Post by sinewav »

Java's sound api is too complicated. It's all super low-level stuff. I couldn't make sense of it after 3 days of reading. I'm learning Python right now. Seems to have more of the type of support I'm looking for.
Paizo
Posts: 9
Joined: Fri Apr 16, 2010 1:18 pm

Re: Processing Audio Data

Post by Paizo »

just google it :D

<spam>
User avatar
sinewav
Graphic Artist
Posts: 6497
Joined: Wed Jan 23, 2008 3:37 am
Contact:

Re: Processing Audio Data

Post by sinewav »

Well, I've spent over a dozen hours searching for a solution to this problem of mine. You see, I want to play a sound file at a different pitch. Apparently there is no sound API that does this automatically, so you have to do a FFT on a sound array. AND, I can't seem to find an explanation of this I can understand matched with equally understandable code.

So, uh, yeah. Any help would be appreciated. I never imagined such a seemingly simple, rather common activity would be so difficult to find a solution for. I'll be back later to explain a little more about where I'm at in my understanding. I need a break. :x
User avatar
sinewav
Graphic Artist
Posts: 6497
Joined: Wed Jan 23, 2008 3:37 am
Contact:

Re: Processing Audio Data

Post by sinewav »

Ok, this is what I know so far, which isn't much.

I'm using Python. I've installed pygame, which seems to be the best supported, active module with sound capabilities. The pygame.mixer module has all the basics for playing, mixing, and adjusting pan, volume and fade -- but nothing for pitch. Pygame does come with some functions under the heading sndarry, which as the name implies, let's me load a sound file into an array, then later make that array a sound object.

Where I'm hung up is what to do with the array. I don't really understand what I've read about the subject, but I think I need to transform each chunk of the array so the end result is either larger or smaller, thus causing the pitch to be higher or lower on output -- something about dividing by the ratio of two sample rates I think.

Even if someone can point me to a resource, a website, a book, anything; even if it means learning quite a bit. I think I'm up for the challenge.
User avatar
Jip
Round Winner
Posts: 397
Joined: Sat Sep 26, 2009 5:32 pm

Re: Processing Audio Data

Post by Jip »

I dont have experience myself there. But did you stumble over this link allready?
User avatar
sinewav
Graphic Artist
Posts: 6497
Joined: Wed Jan 23, 2008 3:37 am
Contact:

Re: Processing Audio Data

Post by sinewav »

Jip wrote:I dont have experience myself there. But did you stumble over this link allready?
Yes, several times, but I don't understand what I'm looking at.
User avatar
AI-team
Shutout Match Winner
Posts: 1020
Joined: Tue Jun 23, 2009 6:17 pm
Location: Germany/Munich
Contact:

Re: Processing Audio Data

Post by AI-team »

If you're on windows you should have a look at C#'s audio class.
http://msdn.microsoft.com/en-us/library ... o.31).aspx
  
 
"95% of people believe in every quote you post on the internet" ~ Abraham Lincoln
 
 
User avatar
sinewav
Graphic Artist
Posts: 6497
Joined: Wed Jan 23, 2008 3:37 am
Contact:

Re: Processing Audio Data

Post by sinewav »

AI-team wrote:If you're on windows you should have a look at C#'s audio class.
http://msdn.microsoft.com/en-us/library ... o.31).aspx
I'm on Linux. That looks promising, but I'm only going to learn C# as a last resort. I haven't heard anything good about it yet.

But, I'm now requesting help for payment. That means, I'll send any of you money (through PayPal) if you can write a well commented code snippet for me. The Python modules I currently have installed are pygame, numpy, and scipy. This is what I've got so far:

Code: Select all

import time, numpy, pygame.mixer, pygame.sndarray
from scikits.samplerate import resample

pygame.mixer.init(44100,-16,2,4096)

# choose a file and make a sound object 
sound_file = "tone.wav"
sound = pygame.mixer.Sound(sound_file)

# load the sound into an array
snd_array = pygame.sndarray.array(sound)

# resample. args: (target array, ratio, mode), outputs ratio * target array.
# this outputs a bunch of garbage and I don't know why.
snd_resample = resample(snd_array, 1.5, "sinc_fastest")

# take the resampled array, make it an object and play for 2 seconds. 
snd_out = pygame.sndarray.make_sound(snd_resample)
snd_out.play()
time.sleep(2)
The main APIs: scikits.samplerate, pygame.sndarray
User avatar
sinewav
Graphic Artist
Posts: 6497
Joined: Wed Jan 23, 2008 3:37 am
Contact:

Re: Processing Audio Data

Post by sinewav »

Update: Stackoverflow came through just before I lost all hope. I now have the necessary tools to write this dumb little program of mine. I anticipate another frustrating episode when I try to package the program as something others can use. Cross that bridge when I come to it.
User avatar
AI-team
Shutout Match Winner
Posts: 1020
Joined: Tue Jun 23, 2009 6:17 pm
Location: Germany/Munich
Contact:

Re: Processing Audio Data

Post by AI-team »

stackoverflow is awesome, they are able to answer every question you have
  
 
"95% of people believe in every quote you post on the internet" ~ Abraham Lincoln
 
 
Post Reply