Results 1 to 35 of 35

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

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2015
    Posts
    2,671

    [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
    11.16.2021 - added saving to WAV
    Attached Files Attached Files

  2. #2
    New Member
    Join Date
    Mar 2016
    Location
    Providence, RI
    Posts
    14

    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
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,181

    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
    PowerPoster
    Join Date
    Feb 2015
    Posts
    2,671

    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
    Providence, RI
    Posts
    14

    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
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,181

    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
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,181

    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
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    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
    Providence, RI
    Posts
    14

    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
    Providence, RI
    Posts
    14

    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
    Providence, RI
    Posts
    14

    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
    Providence, RI
    Posts
    14

    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
    PowerPoster
    Join Date
    Feb 2015
    Posts
    2,671

    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
    Providence, RI
    Posts
    14

    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
    Providence, RI
    Posts
    14

    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
    Providence, RI
    Posts
    14

    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
    Providence, RI
    Posts
    14

    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.

  24. #24
    Member
    Join Date
    Apr 2019
    Posts
    51

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

    Hi Trick,

    Thank you for the noise generator, it finally came the time to use it

    I found your Sound Class very useful. However, when I tried to add Volume and Pan properties (from your MP3 player) to the class, the IDE crashes because of the ASM patch.

    Is there a way to add waveOutSetVolume and waveOutGetVolume functions to the class ?!

    Thank you.

    Радо

  25. #25

  26. #26
    Frenzied Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    1,289

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

    Here is another version of ctlKnob.cls without flickering. Just some fixes I do and now works without flickering.
    Attached Files Attached Files

  27. #27
    Frenzied Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    1,289

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

    -----

  28. #28
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    2,223

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

    Trick, this is good stuff and certainly superior to MCIsendString which seems to introduce so much noise.

    Do you have a method of saving the recorded sound to a .wav file?
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  29. #29

  30. #30
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    2,223

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

    Thankyou Trick, I am looking to incorporate that code but it has a user defined type of SONG that I do not know how to define. I was going to look at the code for your trickComposer but I see the links you provided contain only a binary demo and not the full code so I can't glean what I need to pass to this function as type SONG.
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  31. #31

  32. #32
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    2,223

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

    Quote Originally Posted by The trick View Post
    The Song class just provides information about track. Just use mmioWrite function to write your audio buffer.
    I think that may be beyond my capabilities at present, but I thank you for your time Trick!
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  33. #33

  34. #34
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    2,223

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

    Crikey Trick, that was damn quick and far more than expected. I will dive into your code and see what I can learn. Thank you very much.
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  35. #35
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    2,223

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

    Trick, that code is invaluable. I have added clear sound recording to my app. I am going through your code line by line to ensure I know what it is doing and learn from it.
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

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
  •  



Click Here to Expand Forum to Full Width