dcsimg
Results 1 to 23 of 23
  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2015
    Posts
    1,051

    [VB6] TrickSound - class for working with audio.


    Hi everyone!
    I've created the new version of my clsTrickSound class that i used in the vocoder project. This class provides the simple interface to playback and capture sound. It doesn't require any dependencies and works autonomously. This class has the NewData event that is raised when the internal buffer with sound data has been filled or a device requires the new part of sound data. In order to playback sound you should call the InitPlayback function, to capture - InitCapture. Then you should call StartProcess in order to begin playback/capture. I've made the two examples of the usage of this class: simple synthesizer and simple recorder. Thanks for attention.
    Regards,
    Кривоус Анатолий (The trick).

    Updates:
    07.22.2016 - version 2.1
    Attached Files Attached Files

  2. #2
    New Member
    Join Date
    Mar 2016
    Location
    Charlestown, RI
    Posts
    13

    Re: [VB6] TrickSound - class for working with audio.

    I want to thank you for your masterpiece. I ran it in vb 6.0 as soon as I downloaded your zip file. How do I stop the siren from blaring? Does it eventually stop? I ended up using the X button on the top right of the Form. I only added the tricksound2 class. What do I do with the Folders or are they for experimenting with? I have been looking for something like this since the beginning of the century. Everyone said I had to use a wave file and couldn't generate the sounds in memory.

  3. #3
    Fanatic Member
    Join Date
    Oct 2008
    Posts
    960

    Re: [VB6] TrickSound - class for working with audio.

    Quote Originally Posted by The trick View Post

    Hi everyone!
    I've created the new version of my clsTrickSound class that i used in the vocoder project. This class provides the simple interface to playback and capture sound. It doesn't require any dependencies and works autonomously. This class has the NewData event that is raised when the internal buffer with sound data has been filled or a device requires the new part of sound data. In order to playback sound you should call the InitPlayback function, to capture - InitCapture. Then you should call StartProcess in order to begin playback/capture. I've made the two examples of the usage of this class: simple synthesizer and simple recorder. Thanks for attention.
    Regards,
    Кривоус Анатолий (The trick).
    Cool VB class, but it has a bug. Everything works, except one key part. And that is your StopProcess function, which is SUPPOSED TO stop sound input buffer getting or sound output buffer setting, does NOT stop it, and input getting or output setting continues until I run the Uninitialize function. Unfortunately, uninitializing the whole thing is a pretty DRASTIC action, just to stop a buffer from playing or recording. I don't even know how your thing works. I just treat it like a black-box, that works to do what it does. I've tried looking at the code, but the problem is it is SO COMPLICATED that I can't debug it myself. So I don't know why it's not working, just the fact that it is not working. PLEASE fix this. It would even be a potential REPLACEMENT for the DirectX8 sound stuff I'm doing, because it's so much easier to use. However, I'll be forced to continue using DirectX8, until your product is bug-free. The software I'm writing MUST have a way to stop playing or recording, without uninitializing the entire object (which then requires reinitializing it later, rather than just restarting the already initialized object later). So yeah, that bug is a NO GO for the software application I'm writing. I'll stick with DirectX8 until you fix the bug.
    Last edited by Ben321; Jul 21st, 2016 at 07:44 PM.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2015
    Posts
    1,051

    Re: [VB6] TrickSound - class for working with audio.

    Quote Originally Posted by Ben321 View Post
    Cool VB class, but it has a bug. Everything works, except one key part. And that is your StopProcess function, which is SUPPOSED TO stop sound input buffer getting or sound output buffer setting, does NOT stop it, and input getting or output setting continues until I run the Uninitialize function. Unfortunately, uninitializing the whole thing is a pretty DRASTIC action, just to stop a buffer from playing or recording. I don't even know how your thing works. I just treat it like a black-box, that works to do what it does. I've tried looking at the code, but the problem is it is SO COMPLICATED that I can't debug it myself. So I don't know why it's not working, just the fact that it is not working. PLEASE fix this. It would even be a potential REPLACEMENT for the DirectX8 sound stuff I'm doing, because it's so much easier to use. However, I'll be forced to continue using DirectX8, until your product is bug-free. The software I'm writing MUST have a way to stop playing or recording, without uninitializing the entire object (which then requires reinitializing it later, rather than just restarting the already initialized object later). So yeah, that bug is a NO GO for the software application I'm writing. I'll stick with DirectX8 until you fix the bug.
    Thank you very much for testing. I've fixed this bug.

  5. #5
    New Member
    Join Date
    Mar 2016
    Location
    Charlestown, RI
    Posts
    13

    Re: [VB6] TrickSound - class for working with audio.

    Hi I replaced my folder with the latest tricksound.zip file but doing so I lost the Form1 file that plays the siren. How do I play the siren now?

  6. #6

  7. #7
    Fanatic Member
    Join Date
    Oct 2008
    Posts
    960

    Re: [VB6] TrickSound - class for working with audio.

    There's one other thing I noticed in your TrickSound class. It is this line of code
    Code:
    mSmpCount = BufferSampleCount - (BufferSampleCount Mod mFormat.nBlockAlign)
    This line appears in both the InitCapture and InitPlayback methods.

    This line of code is designed to guaranty that the sample count is a multiple of the BlockAlign value. However, that is completely unneeded. It is the BYTE count (not sample count) that must be equal to a multiple of the BlockAlign value. The number of samples in a buffer can be any number. The line of code in question should instead say
    Code:
    mSmpCount = BufferSampleCount

  8. #8

  9. #9
    Fanatic Member
    Join Date
    Oct 2008
    Posts
    960

    Re: [VB6] TrickSound - class for working with audio.

    Quote Originally Posted by The trick View Post
    This value should be multiple of channels.
    Actually when it comes to stereo audio data, a single sample is defined as a PAIR of value. 48000 samples-per-second of stereo audio, means 48000 VALUE PAIRS per seconds.

  10. #10
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,999

    Re: [VB6] TrickSound - class for working with audio.

    what about MultiTrack recording? how many samples then?


  11. #11
    New Member
    Join Date
    Mar 2016
    Location
    Charlestown, RI
    Posts
    13

    Re: [VB6] TrickSound - class for working with audio.

    I still can't shut off the siren. I used snd.stopprocess after snd.startprocess but the computer hangs up but the siren did stop but I had to manually end it.

  12. #12

  13. #13
    New Member
    Join Date
    Mar 2016
    Location
    Charlestown, RI
    Posts
    13

    Re: [VB6] TrickSound - class for working with audio.

    Quote Originally Posted by The trick View Post
    john02813, please attach your project.
    This is the siren zip file from your article! I didn't include the module as it is still the same as it was when I downloaded the zip file from you.
    I tried using a Timer between snd.StartProcess and snd.StopProcess but it didn't do any good.
    Option Explicit

    Const pi = 3.1415926

    Dim WithEvents snd As clsTrickSound2

    Private Sub Form_Load()
    Set snd = New clsTrickSound2
    snd.InitPlayback 1, 44100, 8, 4096 ' // 44.1 KHz, 8 bit, Mono
    snd.StartProcess
    snd.StopProcess
    End

    End Sub

    Private Sub snd_NewData(ByVal DataPtr As Long, ByVal CountBytes As Long)
    Static phase1 As Single, phase2 As Single
    Static delta1 As Single, delta2 As Single

    Dim buffer() As Byte
    Dim index As Long

    ReDim buffer(CountBytes - 1)
    delta2 = 2 * pi * 0.5 / 44100 ' // LFO delta phase (0.5 Hz frequency modulation)

    For index = 0 To CountBytes - 1
    buffer(index) = (phase1 > 0.5) And &HFF
    delta1 = (Sin(phase2) * 300 + 700) / 44100 ' // Generation from (700 - 300 = 400) to (700 + 300 = 1000) Hz
    phase1 = phase1 + delta1: If phase1 > 1 Then phase1 = phase1 - 1
    phase2 = phase2 + delta2: If phase2 > 2 * pi Then phase2 = phase2 - 2 * pi
    Next

    snd.CopyData DataPtr, VarPtr(buffer(0)), CountBytes

    End Sub

  14. #14

  15. #15
    New Member
    Join Date
    Mar 2016
    Location
    Charlestown, RI
    Posts
    13

    Re: [VB6] TrickSound - class for working with audio.

    Quote Originally Posted by The trick View Post
    What's the sense of that code?
    It is the code that was in the zip file for siren. I added snd.stopprocess in hopes that it would stop the siren sound but obviously it didn't work.

  16. #16

  17. #17
    New Member
    Join Date
    Mar 2016
    Location
    Charlestown, RI
    Posts
    13

    Re: [VB6] TrickSound - class for working with audio.

    Quote Originally Posted by The trick View Post
    I don't understand your goal. You may play sound for some time and then stop it. Considering your code you begin to play sound and immediately stop it and end the program. What the behavior you expected?
    I jusst downloaded the code that was in siren.zip and it played the siren forever so I needed a way to stop the siren so I used snd.StopProcess in order to stop the siren noise. There is only one way to stop the sound and that is to click on the X on the top Right hand side of the Form. I tried to use sleep 20 then End but it didn't work. All I want is a way to limit how long the siren will play. You said that you had fixed the bug but it still plays forever or until I end the program.

  18. #18

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2015
    Posts
    1,051

    Re: [VB6] TrickSound - class for working with audio.

    I jusst downloaded the code that was in siren.zip and it played the siren forever so I needed a way to stop the siren so I used snd.StopProcess in order to stop the siren noise. There is only one way to stop the sound and that is to click on the X on the top Right hand side of the Form. I tried to use sleep 20 then End but it didn't work. All I want is a way to limit how long the siren will play. You said that you had fixed the bug but it still plays forever or until I end the program.
    When do you need to stop the sound? You stop it immediately in your example. If you want to play the sound for some time use a timer. You can't use Sleep because it freezes the calling thread. You shouldn't use End at all, forget about that statement.

  19. #19
    New Member
    Join Date
    Mar 2016
    Location
    Charlestown, RI
    Posts
    13

    Re: [VB6] TrickSound - class for working with audio.

    Quote Originally Posted by The trick View Post
    When do you need to stop the sound? You stop it immediately in your example. If you want to play the sound for some time use a timer. You can't use Sleep because it freezes the calling thread. You shouldn't use End at all, forget about that statement.
    I use this but the siren starts playing again after the timer loop expires.

    Option Explicit

    Const pi = 3.1415926
    Dim ThisTime
    Dim WithEvents snd As clsTrickSound2

    Private Sub Form_Load()
    Set snd = New clsTrickSound2
    snd.InitPlayback 1, 44100, 8, 4096 ' // 44.1 KHz, 8 bit, Mono
    snd.StartProcess
    ThisTime = Timer
    Do
    Loop While ThisTime + 4 * 0.7 > Timer
    snd.StopProcess
    End Sub

    Private Sub snd_NewData(ByVal DataPtr As Long, ByVal CountBytes As Long)
    Static phase1 As Single, phase2 As Single
    Static delta1 As Single, delta2 As Single

    Dim buffer() As Byte
    Dim index As Long

    ReDim buffer(CountBytes - 1)
    delta2 = 2 * pi * 0.5 / 44100 ' // LFO delta phase (0.5 Hz frequency modulation)

    For index = 0 To CountBytes - 1
    buffer(index) = (phase1 > 0.5) And &HFF
    delta1 = (Sin(phase2) * 300 + 700) / 44100 ' // Generation from (700 - 300 = 400) to (700 + 300 = 1000) Hz
    phase1 = phase1 + delta1: If phase1 > 1 Then phase1 = phase1 - 1
    phase2 = phase2 + delta2: If phase2 > 2 * pi Then phase2 = phase2 - 2 * pi
    Next

    snd.CopyData DataPtr, VarPtr(buffer(0)), CountBytes

    End Sub

  20. #20

  21. #21
    New Member
    Join Date
    Mar 2016
    Location
    Charlestown, RI
    Posts
    13

    Re: [VB6] TrickSound - class for working with audio.

    Quote Originally Posted by The trick View Post
    Look at that:
    Code:
    Private Sub Timer1_Timer()
        snd.StopProcess
    End Sub
    There is no way to activate Timer1_Timer. I had snd.StopProcess in Form1 but the program kept running even though the siren stopped playing.

  22. #22
    New Member
    Join Date
    Mar 2016
    Location
    Charlestown, RI
    Posts
    13

    Re: [VB6] TrickSound - class for working with audio.

    ok I ran the revised siren and it played about 5 seconds then ended normally. How do I get the siren to play a little longer than 5 seconds?
    Do I use a Timer loop in the sub Timer1_Timer like this:
    ThisTime = Timer
    Do
    Loop While ThisTime + 4 * 0.7 > Timer
    snd.StopProcess
    ???

  23. #23
    New Member
    Join Date
    Mar 2016
    Location
    Charlestown, RI
    Posts
    13

    Re: [VB6] TrickSound - class for working with audio.

    Never mind. I figured out that I change the Interval in properties to get the siren to play longer. I changed it to 6000 and everything is great now. I just wanted to be able to make sound effects as I am an old man with nothing to do but program to keep busy.

Tags for this Thread

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width