Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Audio manipulation with Java [closed]

The smallest unit of a digital image is a pixel. What is the smallest unit of digital sound? what can be considered to be a pixel for sound? How can we use java to manipulate it?

like image 503
user3177843 Avatar asked Dec 26 '22 15:12

user3177843


2 Answers

The smallest unit of sound is known as a frame. For 8 bit mono it will be a single byte. For stereo 16 bit it will be 4 bytes.

How can we use Java to manipulate it?

That depends on what you want to do with it. You will need to be a lot more specific to get reasonable answers.

Some possible operations are:

  • Volume change
  • Pan
  • Speed or slow the play rate, with or without..
  • Pitch shift
  • Spectrum analysis..

.. how many hertz or samples can the speaker produce?

That depends largely on the speaker. Speakers have all different types of dynamic ranges, usually in a kind of 'bell curve' with no absolute upper or lower limits.

Does that mean it takes 44KB to store 1 second of music that is CD Quality?

Each frame of CD quality sound contains 4 bytes, given it is stereo, 16 bit. Multiply 4 bytes by 44100 to calculate the number of bytes per second.

What's the difference between mono and stereo?

Mono has one channel, stereo has two.

What I want to do is manipulate individual units of sound and also - to create a custom musical instrument/synth.

It is not so hard to generate a simple sinusoidal sound in code. See Beeper for an example.

A lot of other effects can be created by playing around with the ADSR (Attack, Decay, Sustain, Release) envelope of a sound. For example, applying the ADSR envelope of a guitar note to a piano tone, will make it sound uncannily like a guitar, and vice versa.

What is channel? Is it like speaker - Left speaker is one channel and right speaker is another?

Pretty much. Mono sounds like rubbish (IMO), while stereo can make the different instruments sound like they are coming from different positions, just like if the band were sitting right in front of you.

5.1 channel sound is a little more complicated, and usually1 it 'cheats' by simply.

  • Putting the left channel through the left speaker(s).
  • Putting the right channel through the right speaker(s).
  • Mixing them both equally and putting that through the center speaker.
  • Filtering for just the low frequency sound and putting that through the single woofer or bass speaker. The human ear cannot easily tell where low frequency sounds are coming from, so that is acceptable. The woofer can be placed anywhere in the room, and still sound just the same.

  1. To be honest, I do not know of any sound format that actually stores 5 or 6 channels for the sound, I think it is all separated out (for the woofer) or mixed together (for the center speaker) in hardware at run-time. Java Sound will only deal with one or 2 channels directly, in any case.
like image 191
Andrew Thompson Avatar answered Dec 28 '22 08:12

Andrew Thompson


The smallest unit of digital sound is a sample -- the signal level at a particular point in time. [But see addendum below.]

To use Java to manipulate it: If you have to ask this question, you probably want to go looking for libraries someone else has written.

But if you want to know in general what's involved: Read in the sound file. If it was in a compressed format (such as MP3), unpack it. That will give you a very long array/vector of samples. You can cut-and-paste sections of that to edit the recording, or scale it to make it softer or louder (beware of "clipping", which results when you try to exceed the maximum volume). More complicated manipulations are possible, but that's a full course in digital signal processing which I'm not going to try to do here -- websearch that phrase, especially in conjunction with sound or audio or music should find more information.

You can also generate your own audio by producing the samples programmatically. A signal which varies sinusoidally from sample to sample produces a pure tone. Other repeating shapes add overtones of various kinds. Varying the frequency of the repetition changes the pitch. Adding several signals together (while watching out for clipping) mixes them into a single signal. And so on.

Note that MIDI is not "digital sound" -- it's a digital score. It describes what notes should be played when, but it's up to the synth to turn that into sound.

ADDENDUM: I haven't heard the term "frame" before (see Andrew's answer), but I'll believe it. I think of samples because I'm thinking at the hardware layer, but distinguishing that from sample meaning an audio clip is a Good Thing so I'd bet frame is indeed more correct/current.

like image 32
keshlam Avatar answered Dec 28 '22 07:12

keshlam