Android Question Mixing audiostream

Discussion in 'Android Questions' started by sorex, Feb 24, 2015.

  1. sorex

    sorex Expert Licensed User

    Hello,

    Did anyone ever succeed to do mixing of 2 (or more) audiostreams?

    When I have 2 streams running it first seemed to work fine but after seconds
    there is starting to be some delays.

    After half a minute it's 10+ seconds already.

    I guess it is playing each stream buffer after each other instead of mixing them for sumiltanious play.
     
  2. KZero

    KZero Active Member Licensed User

    try to increase the buffered bytes before starting to playback

    if the incoming audio packets are encoded try decoding it in a separate thread
     
  3. sorex

    sorex Expert Licensed User

    I don't see any option to change the buffer size?

    but like I said it seems it's putting the to be played buffers in a queue to be played.
     
  4. KZero

    KZero Active Member Licensed User

    you can do it manually by saving the bytes into byte array before writing to the audiostreamer
    or you can try AudioTrack Library it has buffersize option
     
  5. sorex

    sorex Expert Licensed User

    ok, I figured it out.

    It seems to be some kind of Android logic although it makes kind of sense when you think about it.

    I had 1 audiostreamer which I changed to 1 for each connection.

    This seems to skip the stacking of buffered data that caused the long delays after a few seconds.

    So 2 stream players playing different fetched buffers at the same time is what I have now.
     
    KZero likes this.
  6. sorex

    sorex Expert Licensed User

    the only thing I can't get working at the moment is multiple listening stream to the broadcasting phone.

    when the second listening device connects I get this error

    java.lang.IllegalStateException: startRecording() called on an uninitialized AudioRecord.

    altho I dim and init it in the new connection sub of the server

    is this a limitation of audio record?

    Code:
    Dim astr As AsyncStreams
            astr.InitializePrefix(
    NullTrue, NewSocket.OutputStream, "astream")

            
    Dim audioStr As AudioStreamer
            audioStr.Initialize(
    "AudioStream"8000True,16,audioStr.VOLUME_MUSIC)

            
    Dim conn As BrConnection
            conn.audiostreamid=audioStr
            conn.asstreamid=astr
            Connections.Put(NewSocket,conn)
         
            
    Log(audioStr)             
            audioStr.StartRecording   <- error !!!
     
  7. KZero

    KZero Active Member Licensed User

    using different bit-rate and audio format for each initialization may fix it
     
  8. sorex

    sorex Expert Licensed User

    @KZero : I tried it like this

    Code:
    Dim audioStr As AudioStreamer
            
    Try
            audioStr.Initialize(
    "AudioStream"8000True,16,audioStr.VOLUME_MUSIC)      
            
    Log("trying 8000")
            
    Catch
                
    Log("8000 failed")
                
    Try
                
    Log("trying 11000")          
                audioStr.Initialize(
    "AudioStream"11000True,16,audioStr.VOLUME_MUSIC)
                
    Catch
                
    Log("11000 failed")
                    
    Try
                    audioStr.Initialize(
    "AudioStream"16000True,16,audioStr.VOLUME_MUSIC)
                    
    Catch
                    
    Log("16000 failed")
                        
    Try
                        audioStr.Initialize(
    "AudioStream"22000True,16,audioStr.VOLUME_MUSIC)
                        
    Catch
                        
    Log("22000 failed")
                            
    Try
                            audioStr.Initialize(
    "AudioStream"44100True,16,audioStr.VOLUME_MUSIC)
                            
    Catch
                            
    Log("44100 failed")
                            
    End Try              
                        
    End Try
                    
    End Try  
                
    End Try      
            
    End Try
    the first connection goes through at 8000.

    the second one give again that crash with only "trying 8000" in the log, the cath is not even reached?
     
    Last edited: Feb 26, 2015
  9. sorex

    sorex Expert Licensed User

    ignore that, the crash happends later and my log("trying ...") should've been before that init line :)

    back to the code...
     
  10. sorex

    sorex Expert Licensed User

    this fails aswell

    Code:
    Select Case Connections.Size
            
    Case 0
                audioStr.Initialize(
    "AudioStream"8000True,16,audioStr.VOLUME_MUSIC)       
            
    Case 1
                audioStr.Initialize(
    "AudioStream"44100True,16,audioStr.VOLUME_MUSIC)       
            
    End Select
    I guess I can only open up 1 recording stream object.
     
  11. sorex

    sorex Expert Licensed User

    ok, it seems it has nothing to do with the sockets, asyncstream.

    it's pure the definition of 2 audiostreamers that is conflicting somewhere.

    I've attached an example which is just a handfull lines of code that reproduces it.
     

    Attached Files:

  12. KZero

    KZero Active Member Licensed User

    this code worked normally on my samsung note edge but failed on Lenovo A3000

    you should call audioStr.StopRecording before starting the other recorder

    why you need to record the same audio using 2 different AudioStreamers ?
     
  13. sorex

    sorex Expert Licensed User

    I thought it was a requirement to prevent the delays like in the receiver.

    But apparently 1 recorder is enough you just need to send the recorded buffer to the different connected ASstreams.

    It works fine now.
     
    KZero likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice