Results 1 to 7 of 7
  1. #1
    AUser is offline Member
    Join Date
    Oct 2013
    Location
    PA, USA
    Posts
    4
    Rep Power
    0

    Default Reading music from the sound card

    I'm creating MIDI music using a synthesizer, sequencer, and sequence. I'm trying to capture the music (not the MIDI messages) as it's being played so then I have all the data and I can do some Fourier analysis on it. The documentation revolves itself around having music coming in from the microphone, or other ports so what I'm trying to figure out is how to listen in on one of the ports so I can capture the data as it's playing. It all seems confusing as if you can't listen to the music that you're playing? The way I'm playing the music is just using sequencer.start() and then having the thread sleep for a couple of minutes. I understand that method isn't going to work and I'm going to have to multi-thread this, but right now I don't understand how to read in the data while it's being played.

    Anyone know anything about this or offer ideas?

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,424
    Rep Power
    5

    Default Re: Reading music from the sound card

    I'm still not certain what you are trying to do. I know for a fact that you can play a MIDI file and see the MIDI commands as they are processed. But since you said you don't want the MIDI messages, exactly what do you want?

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    AUser is offline Member
    Join Date
    Oct 2013
    Location
    PA, USA
    Posts
    4
    Rep Power
    0

    Default Re: Reading music from the sound card

    The MIDI messages have to be going somewhere that translates a noteOn command into play this instrument for this long with this intensity. That translation then goes somewhere and eventually into sound. I want to grab the data that becomes the "sound" after the MIDI message gets processed. I want to read in all the data then perform some Digital Signal Processing (DSP) particularly a DFT or FFT. Helloooo spectral analysis!

    I also don't want to read in a MIDI file because I've found the music I play in real time (aka. calling sequencer.play()) is more accurate to what the music should sound like compared to its MIDI file format. Also I need to do trial runs and having to generate and handle MIDI files is going to be more cumbersome and I don't want to create that many MIDI files.

    So it comes down to how do I grab/listen/read the actual music data that gets created from a MIDI message and gets played off of the sound card? As long as it's the actual music data it doesn't have to come off the sound card. I'm just assuming I'm going to have to listen to the port that's playing the music and I don't know how to set that up because all of the examples I've found are about doing this with MIDI files or using some input port for a keyboard or microphone.
    Last edited by AUser; 10-17-2013 at 01:16 AM.

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,424
    Rep Power
    5

    Default Re: Reading music from the sound card

    I am not familiar with accessing the actual "data" this is translated to sound. I assume it would be some n bit signal that is generated. That level of information may be within the native support for the MIDI classes. You might look into the Java Media Framework to see if it offers any additional help. If you just want to capture what is coming over the speakers, I have been using TotalRecorder for years. They have a great deal on lifetime updates for the level of version you purchase. And it is relatively inexpensive. It is made by High Criteria. It will store the music in a variety of formats. If you know the format you could use Java to read in the file and do your analysis.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  5. #5
    AUser is offline Member
    Join Date
    Oct 2013
    Location
    PA, USA
    Posts
    4
    Rep Power
    0

    Default Re: Reading music from the sound card

    Again I don't want to have to deal with any files of any type. I only want to deal with files if I'm going to listen to it which I do so people can listen to what I'm creating.

    I did found something worthwhile. Pretty much my music starts like this Trail: Sound (The Java™ Tutorials) . Look for the picture with the sequencer and synthesizer. The music gets sent to "sampled audio system" and that's where anything MIDI related ends. The rest of the process uses AudioSystem and right now I'm using this Wired for sound - Java tutorial - developer Fusion to figure out the logical flow of data. If you're still following along since I want to gather MIDI music generated by the PC I'm using Figure 4 to figure out what I need set up in order to capture the data and HOPEFULLY that will do it.

    Then comes setting up a thread to listen and gather the music as it's being played while another thread is playing the music along with then notifying, closing, ending and stopping threads and other resources I release once the music is done playing. This part I'll figure out.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,863
    Rep Power
    19

    Default Re: Reading music from the sound card

    I think (and this is not something I've done, only done the MIDI side of things) that you use the bits in the sampled package to listen in on audio coming out of the hardware. In your case this should be the MIDI. So you'd have one thread generating the MIDI which is fed into the PC hardware, and another thread listening in on the audio being output from the hardware.

    So my first step would be to create something that simply listens in on audio being played (the javax.sound.sampled package), even if it's just a wav.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    AUser is offline Member
    Join Date
    Oct 2013
    Location
    PA, USA
    Posts
    4
    Rep Power
    0

    Default Re: Reading music from the sound card

    ANSWER
    I found on grepcode.com that there was an AudioSynthesizer interface that allows one to render output audio straight into an AudioInputStream or SourceDataLine, but couldn't figure out how to use it correctly. I later found through a friend that JFugue allows you to save MIDI music as a .wav file. On further inspection it implements the AudioSynthesizer interface and allowed me to convert my MIDI music straight into audio data using an AudioInputStream. I then had to read in from the buffer 4 bytes at a time because that's all the buffer supported and now I had my data. Sort of. Turns out since my audio is 16 bit I needed to take 2 bytes at a time and do some logical operations and byte shifting to get the amplitudes of the data. When I graphed this data it now looks like the waveform of the music. The good thing is when I format the audio data the result is stored into a double and now I just need to store this into a double [] and I'll be set to perform my FFT.
    Last edited by AUser; 10-29-2013 at 09:36 PM.

Similar Threads

  1. Getting sound from sound card
    By crikey in forum Advanced Java
    Replies: 1
    Last Post: 06-18-2013, 09:07 AM
  2. Replies: 4
    Last Post: 06-15-2012, 06:10 AM
  3. Problems with sound in java and USB sound card
    By marblecatdog in forum New To Java
    Replies: 1
    Last Post: 04-19-2011, 12:02 PM
  4. audio capture from sound card
    By kievari in forum Advanced Java
    Replies: 0
    Last Post: 11-03-2010, 07:00 PM
  5. Controlling sound card 'stereo mix' feature
    By sid in forum Advanced Java
    Replies: 0
    Last Post: 10-29-2010, 11:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •