Member 2664
108 entries

Immortal since Jun 17, 2010
Uplinks: 0, Generation 4
mad-scientist and computer programmer looking for something more interesting than most people accept as their future
  • Affiliated
  •  /  
  • Invited
  •  /  
  • Descended
  • BenRayfield’s favorites
    From AsylumSeaker
    Christopher Langan
    From Yissar
    Technology Progress vs....
    From XiXiDu
    The Nature of Self
    From QESelf
    View Point Room Argument...
    From Jorgen
    My Paper on Computer...
    Recently commented on
    From gamma
    Is brain a computer?
    From BenRayfield
    Elections should be done...
    From BenRayfield
    The most dangerous thing...
    From BenRayfield
    Why is there no Content...
    From BenRayfield
    How can a set of computers...
    BenRayfield’s projects
    The human species is rapidly and indisputably moving towards the technological singularity. The cadence of the flow of information and innovation in...

    The Total Library
    Text that redefines...

    Start your own revolution
    Catching up with the future. All major institutions in the world today are grappling to come to terms with the internet. The entertainment...

    Proposal for a multimedia...
    A musical mindstorm on the nature of sound, light, space and subjective experience powered by locally produced energy, heralding the ending of the...
    Now playing SpaceCollective
    Where forward thinking terrestrials share ideas and information about the state of the species, their planet and the universe, living the lives of science fiction. Introduction
    Featuring Powers of Ten by Charles and Ray Eames, based on an idea by Kees Boeke.
    From BenRayfield's personal cargo

    Learning Curve For Audio Programming Reduced
    Project: Proposal for a multimedia playground
    Buffers, byte order, streaming... Forget that complication. Here's the general solution for making your speakers and microphones do anything you want. With only basic Java programming skills (a first year college class) you can do what took me years to learn: Define sound as numbers from -1 to 1 at each instant in time.

    Most people think computer programming is boring and tedious. That's true for a lot of kinds of programs, but building programs to change your voice or create new kinds of musical instruments, and then using them, can be more fun than music-based video games. Its an upgrade from a set path (like the notes you have to play in Guitar Hero) to complete freedom of what you want the speakers and microphone (or electric guitar in the microphone hole) to do. Computers do billions of calculations per second. Your code will run 44100 times per second for normal 44.1 khz audio (same data speed as CDs), so each vibration of the audio you can do many thousands of calculations if you want. That's your new tools for defining interactions between speakers and microphones. I've made it easy enough anyone can learn it.

    Here's an example of how to use it (names of things may change after version 0.4):

    In the same folder as jsoundcard.jar, create a text file called

    import jsoundcard.*;
    public class X implements SoundFunc{
    public static void main(String args[]) throws Exception{ X(), 2, 1, 44100); //2 speakers, 1 microphone, 44.1 khz
    public void readWriteFrame(double frame[]){
    frame[0] = .5*Math.sin(50*frame[2])-frame[1]*.001;
    frame[1] = .4*Math.cos(40*frame[2]);
    //write any code you want as long as it runs fast and keeps numbers in range -1 to 1
    public int frameSize(){ return 3; } //If you want to be able to use up to frame[34], return 35

    What does that code do? It makes a strange echo (if the microphone can hear the speakers) and makes your voice sound scratchy when you talk louder. To play the microphone as it is (on the left speaker), simply use frame[0] = frame[2]; Because there are 2 speakers, frame[0] and frame[1] are where you put the numbers to create those 2 sounds. Those numbers have to be between -1 and 1. After that is a third number for getting the microphone as frame[2]. Math.sin is the sine function in math. Multiplying the left speaker by .5 makes it a little louder than the right speaker which is multiplied by .4. Multiplying the microphone amplitude by 50 makes it higher frequency than multiplying it by 40, but in a kind of screwed up way that makes it vibrate multiple times and then reverse direction in the sine/cosine circle. That's just an example. You can calculate the numbers however you want to create different sound effects. I like to do it by plugging an electric guitar into the microphone hole.

    Install Java Development Kit (JDK) 1.5 or higher and set your PATH to include its folder with javac.exe in it (or use the whole path to javac.exe).

    Type this on the command-line to compile it: javac -cp .;jsoundcard.jar
    (On Linux use colon instead of semicolon)

    Type this on the command-line to run it: java -cp .;jsoundcard.jar X

    Then you hear the sound you just programmed, an interaction between microphone and speakers.

    To make there be less delay between microphone and speakers, in Windows, you can crtl+alt+delete (each time you run the program) and Set Priority of java.exe or javaw.exe to High or Realtime. JSoundCard will detect the increased available speed and use it automatically. It won't use extra cpu. It will just update the sound buffers more often then go back to sleep.

    You can build programs that are 1 file you double-click to run, but that takes more setup in building it (not using it). When programming, what I wrote above is the easiest way to start. I'm building an easier way to use it, but that will be a separate program. This is if you want to keep the code small and simple.

    If you want your new program to be in 1 file that works instantly when anyone double-clicks it, rename jsoundcard.jar to and unzip it. Then change the META-INF/MANIFEST.MF file so it says the Main-Class is X instead of jsoundcard.TestJSoundCard. Then zip all those files, including and X.class (which javac created), into a new zip file. Then rename that zip file to YourProgram.jar. Then double-click YourProgram.jar and it plays your sound effects (interaction between speakers and microphone). That's how anyone with very little training can create their own sound programs. Give YourProgram.jar to your friends, and have them repeat the same steps with YourProgram.jar as you did for jsoundcard.jar, to build their own programs. Or just double-click it to use your new program.

    There is still the problem of how to stop the sound effects (close the program) after double-clicking your new file. You could put at the end of that "main" function this code to make it end after 1 minute: Thread.sleep(60*1000); JSoundCard.stop();

    If you follow these instructions, you've done what took me years to learn. Of course I didn't have anyone giving me the solution. Now lets build that "Multimedia Playground".

    Its a very small software you use to build new audio software. All it does is give you easy access to the sound-card. Future versions will not contain specific sound-effects or other complexity. The point is to be as simple as possible and put that complexity in other programs that use this program. That way theres billions of people who could do audio programming instead of only professionals. It could catch on, if those who try it tell 1 or 2 friends each, who do the same... This really is the simplest it has ever been. I started audio programming 10 years ago (in some of my free time). I build different audio softwares and finally forged the common parts of them into the most simple thing it could be. I've done some things in audio programming that nobody else would have known how to do without reading my code (other programs). Of course I do it by "standing on the shoulders of giants", but to make sure I can stand higher years from now I'm reducing the learning curve for audio programming so new giants can grow for me to stand on. I'm making it simple enough that anyone who wants to learn audio programming can learn it. Hopefully someone who uses this will eventually build some open-source software we all can use later, and we can finally build the "Multimedia Playground" which is some combination of interactive audio and video.

      Add to favorites
    Create synapse

    Ronan Whitteker     Fri, Jun 10, 2011  Permanent link
    Ah yeah man.. much a preciated for that learning curve can be a slippery slope to no gumption!

    Hey it seems like you know a bit about programming and i thought i might tell you my problem and if you have a solution then we could collaborate... I do a little java programming (processing).

    What I do not understand if the best way to sync audio and video (with minimum precalculation).

    I guess triggering the video from the audio but i haven't been able to get less than a whole buffer size worth of latency..

    please help!!


    p.s. ur evlv sftwr s vry nc
    BenRayfield     Fri, Jun 10, 2011  Permanent link
    If you look in the code of JSoundCard, you'll see how I control the sync of speakers and microphone. Its the code that uses my InterpolateBuffer class. There has to be some delay since its 2 different systems and the speaker output depends on what the microphone hears, but it calculates how to smoothly change that delay while keeping it small and avoiding an empty buffer which would make the sound jump. It changes the speed of consuming audio data (.99 to 1.01 usually, interpolated) based on those statistics. I created that system for audio in Java because I found that sometimes the speakers will run at 44.1 khz and the microphone at 44.2 khz, for example, so my code uses one a little faster than the other, interpolating between its data points continuously, to make them match, and it makes them not match a little when it needs to shrink the delay between them, then it pushes the ratio the other direction to balance it at the lower delay, and it continues like that.

    You could use similar code between sound and video. My code (download at SourceForge at the link above) can be slightly modified to sync any audio in Java to anything else... video, mouse movements, anything you can write code to connect it to. Its math is for general synchronizing of things that change speeds continuously.

    In Java you can display any pixels (realtime generated video, for example) using the java.awt.image.MemoryImageSource class. Its only realtime speed if you make the window very small, but I'm happy to have realtime video ability in Java at all, in standard Java with no plugins.
    Ronan Whitteker     Mon, Jun 13, 2011  Permanent link
    oh right thanks..

    yeah I'm not so worried about being realtime as I AM ABOUT BEING IN SYNC.

    lol, I think stretching the audio is getting a bit technical for me..

    but yeah I think a lot of that stuff is beyond me at the moment. I should just focus on my mathematics. Thanks for the help :)

    I think I will download the code and make the jump to genuine JAVA over processing :)