CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 3 of 4 FirstFirst 1234 LastLast
Results 31 to 45 of 54
  1. #31
    Join Date
    Oct 2009
    Posts
    34

    Re: Streaming Audio from one PC to another over a Local Network

    And Yes I have tried...

    Static ExData(MAXTCP) As Byte

    The Same Error.

  2. #32
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Streaming Audio from one PC to another over a Local Network

    OK, ExData is a Variant, not a Byte array. That would seem to explain why the error is a type mismatch. I think m$ goofed up there. It's being used as a string however, so it would have made more sense to declare it as a string.

    And declaring it as Byte didn't work because it still wasn't an array being passed, only one byte.

    Two things come to mind which might work. One is to create a UDT for ExData, and the other is to use StrConv() to convert the string data into a Byte array. StrConv() would be the easier one to try, though slower.

    Try the following
    Declare this with the other variables:
    Code:
    Dim ExtraBytes() As Byte
    Put this in the routine in place of the line that raises the error:
    Code:
    ExtraBytes = StrConv(ExData(Index), vbFromUnicode)
    Call .SaveStreamBuffer(Index, ExtraBytes) ' Save the current wave data to the wave buffer
    You might also change ExData to a String, but try it as is first.
    Last edited by WizBang; October 12th, 2009 at 07:35 AM.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  3. #33
    Join Date
    Oct 2009
    Posts
    34

    Re: Streaming Audio from one PC to another over a Local Network

    Quote Originally Posted by WizBang View Post
    Try the following
    Declare this with the other variables:
    Code:
    Dim ExtraBytes() As Byte
    Put this in the routine in place of the line that raises the error:
    Code:
    ExtraBytes = StrConv(ExData(Index), vbFromUnicode)
    Call .SaveStreamBuffer(Index, ExtraBytes) ' Save the current wave data to the wave buffer
    I tried that and the error stops with 8000Hz, 16bit, Stereo
    Before it used to work for a few seconds then error - Type Mismatch
    And the code did get to the new Call .SaveStreamBuffer........ but just once.

    I then tried 11025Hz, 16bit, Stereo
    Sound output from the Client for just a second, then stops, but it's still streaming, being recieved at 50kbs from the router, No error but No sound.

    But if I turn the Server OFF, the Client starts putting sound out for a few seconds, then goes into crackles.

    I also change ExData to a String = Same result.

    So looks like we are getting somewhere.

    Thanks again for looking.

  4. #34
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Streaming Audio from one PC to another over a Local Network

    I'm wondering about this line:
    Code:
    ExData(Index) = MidB(ExData(Index), 1) & MidB(WaveData, 1) ' Sync wave bits...
    Since the second parameter being passed to MidB() is a 1, it doesn't even look like it would do anything at all. The entire string should be returned, so my only guess is that they did it because they declared ExData as a Variant. However, since WaveData is a byte array, it would appear that only one byte would be returned. I'm not so sure that's what should happen.

    Try it this way:
    Code:
    ExData(Index) = ExData(Index) & StrConv(WaveData, vbUnicode)
    This is not very efficient, and of course, it only has to be converted back to a byte array anyway. But if it works, then we can revamp the code to use byte arrays, and probably CopyMemory to put all the bytes together.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  5. #35
    Join Date
    Oct 2009
    Posts
    34

    Re: Streaming Audio from one PC to another over a Local Network

    Quote Originally Posted by WizBang View Post
    I'm wondering about this line:
    Code:
    ExData(Index) = MidB(ExData(Index), 1) & MidB(WaveData, 1) ' Sync wave bits...
    Try it this way:
    Code:
    ExData(Index) = ExData(Index) & StrConv(WaveData, vbUnicode)
    This is all well above my skills in VB, but that is why I came to the Guru's here in the first place.

    I tried that including the other mods in the code you gave me at 11025Hz, 16bit, Stereo.

    Roughly the same as last time, streaming starts, sound output in the Client starts, then stops, but still streaming 50kbs through the router.

    Again when I turn the Server off, the Client sounds like it tries to play the back log of sound, then it ends in crackles.

    But the lower quality streaming sound is the same as before, unaffected, .

    Thanks for looking.

  6. #36
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Streaming Audio from one PC to another over a Local Network

    What is the value of the Index variable used in "ExData(Index)"? Does it change while the streaming is going on? Try putting Debug.Print Index on a line above the second call to SaveStreamBuffer, and see what it's doing. Obviously, you'll have to be running it in the IDE for debug to work.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  7. #37
    Join Date
    Oct 2009
    Posts
    34

    Re: Streaming Audio from one PC to another over a Local Network

    Quote Originally Posted by WizBang View Post
    What is the value of the Index variable used in "ExData(Index)"? Does it change while the streaming is going on? Try putting Debug.Print Index on a line above the second call to SaveStreamBuffer, and see what it's doing. Obviously, you'll have to be running it in the IDE for debug to work.
    The Value is 1, and it does not change.

    Just as a matter of testing, I tried just before the first Call to SaveStreamBuffer.
    Same = 1 and it does not change when it's streaming either at the low qualities or higher.

    Thanks again.

  8. #38
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Streaming Audio from one PC to another over a Local Network

    OK, so it sounds as if there is always just one element of the ExData array, which seems to suggest, by the rest of the code you've posted, that there is only one winsock being used. I'd guess it's because you're only streaming one way.

    So you might be able to simplify things a bit there. What I'd suggest, is to make ExData a byte array like WaveData, and Redim Preserve it to also hold the WaveData, then CopyMemory can be use to fill in those bytes with the WaveData. Or a separate array could be used. Either way, this will avoid the use of StrConv(), and therefore may have a better chance of working.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  9. #39
    Join Date
    Oct 2009
    Posts
    34

    Re: Streaming Audio from one PC to another over a Local Network

    Quote Originally Posted by WizBang View Post
    OK, so it sounds as if there is always just one element of the ExData array, which seems to suggest, by the rest of the code you've posted, that there is only one winsock being used. I'd guess it's because you're only streaming one way.
    There is one Winsock in ithe server, and one Winsock in the Client.

    Quote Originally Posted by WizBang View Post
    So you might be able to simplify things a bit there. What I'd suggest, is to make ExData a byte array like WaveData, and Redim Preserve it to also hold the WaveData, then CopyMemory can be use to fill in those bytes with the WaveData. Or a separate array could be used. Either way, this will avoid the use of StrConv(), and therefore may have a better chance of working.
    Could you give me some Code examples/changes like before, as this is a little above me.

    Thanks again WizBang.

  10. #40
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Streaming Audio from one PC to another over a Local Network

    Something like the following should work, hopefully. I only included the lines effected by the changes, so if ExData or ExBytes are referenced elsewhere, you'll need to address those too.
    Code:
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpDest As Any, lpSource As Any, ByVal cbCopy As Long)
    Code:
    Static ExBytes As Long ' Extra bytes in frame buffer
    Static ExData() As Byte ' Extra bytes from frame buffer
    Code:
                If (ExBytes = 0) Then                ' Was there leftover data from last time
                    If (.waveChunkSize <= TCPSocket(Index).BytesReceived) Then ' Can we get and entire wave buffer of data
                        Call TCPSocket(Index).GetData(WaveData, vbByte + vbArray, .waveChunkSize) ' Get 1 wave buffer of data
                        Call .SaveStreamBuffer(Index, WaveData) ' Save wave data to buffer
                        Call .AddStreamToQueue(Index)       ' Queue current stream for playback
                    Else
                        ExBytes = TCPSocket(Index).BytesReceived ' Save Extra bytes
                        Call TCPSocket(Index).GetData(ExData, vbByte + vbArray, ExBytes) ' Get Extra data
                    End If
                Else
                    Call TCPSocket(Index).GetData(WaveData, vbByte + vbArray, .waveChunkSize - ExBytes) ' Get leftover bits
                    ReDim Preserve ExData(ExBytes + UBound(WaveData))
                    CopyMemory ByVal VarPtr(ExData(ExBytes)), ByVal VarPtr(WaveData(0)), UBound(WaveData) + 1
                    Call .SaveStreamBuffer(Index, ExData) ' Save the current wave data to the wave buffer
                    Call .AddStreamToQueue(Index)           ' Queue the current wave stream
                    ExBytes = 0                      ' Clear Extra byte count
                    'ReDim ExData(0)                      ' Clear Extra data buffer
                End If
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  11. #41
    Join Date
    Oct 2009
    Posts
    34

    Resolved Re: Streaming Audio from one PC to another over a Local Network

    Quote Originally Posted by WizBang View Post
    Something like the following should work, hopefully. I only included the lines effected by the changes, so if ExData or ExBytes are referenced elsewhere, you'll need to address those too.
    I searched and ExData or ExBytes are NOT referenced elsewhere.

    I put your code in, and the tests are as follows.

    11025Hz, 16bit, Stereo = Now Working unbroken steady stream at +/- 45kbs

    22050Hz, 16bit, Stereo = Now Working unbroken steady stream at +/- 90kbs

    44100Hz, 16bit, Stereo = Now Working unbroken steady stream at +/- 180kbs

    Absolutely Fantastic, WizBang you are a true Guru.
    I don't know how to thank you, I can stop pulling my hair out now.

    It all seams stable up to now, would there be anything to look out for memory problem wise ?

  12. #42
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Streaming Audio from one PC to another over a Local Network

    Great! So glad to know it worked!

    As for your memory question, there doesn't appear to be any potential problems related to the changes I made. But it's always good to keep an eye on the resource usage as it runs. If there's a memory leak, it will eventually show up.
    I don't know how to thank you, I can stop pulling my hair out now.
    You can use the "Rate this post" link for any post in any thread which you want to rate. You can also rate a thread itself, using the Rate Thread pull-down at the top of the thread. Lastly, when your own question has been resolved, use the Thread Tools pull-down to mark the thread resolved (or the related option when replying).
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  13. #43
    Join Date
    Oct 2009
    Posts
    34

    Resolved Re: Streaming Audio from one PC to another over a Local Network

    Quote Originally Posted by WizBang View Post
    You can use the "Rate this post" link for any post in any thread which you want to rate. You can also rate a thread itself, using the Rate Thread pull-down at the top of the thread. Lastly, when your own question has been resolved, use the Thread Tools pull-down to mark the thread resolved (or the related option when replying).
    Done, Done & Done.

    Thanks again mate, much appreciated.

  14. #44
    Join Date
    Jun 2014
    Posts
    35

    Re: [RESOLVED] Streaming Audio from one PC to another over a Local Network

    very thnx to your post ,...BriansBrain

    and i need your modefied version of this project

  15. #45
    Join Date
    Jun 2014
    Posts
    35

    Re: [RESOLVED] Streaming Audio from one PC to another over a Local Network

    sorry i didnot read the solution...

    now i done the solution and the fantastic project is work at stereo mode but my log is:

    stereo - 8bit - 22.05 khz IS 44.3 kb/s........ really its wonderfull

    but now i have problem...

    i use this program via week WIFI Signal and when the signal <= 5% the program disconnected and i have to close the Server And The Client and run them again...

    i want solve by ((Auto Reconnect))...


    can any one help me

Page 3 of 4 FirstFirst 1234 LastLast

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured