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
Last edited by The trick; Nov 16th, 2021 at 01:04 PM.
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.
Re: [VB6] TrickSound - class for working with audio.
Originally Posted by The trick
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.
Re: [VB6] TrickSound - class for working with audio.
Originally Posted by Ben321
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.
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
Re: [VB6] TrickSound - class for working with audio.
Originally Posted by The trick
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.
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.
Re: [VB6] TrickSound - class for working with audio.
Originally Posted by The trick
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
Re: [VB6] TrickSound - class for working with audio.
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?
Re: [VB6] TrickSound - class for working with audio.
Originally Posted by The trick
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.
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.
Re: [VB6] TrickSound - class for working with audio.
Originally Posted by The trick
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
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
???
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.
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 ?!
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.
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.
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.
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.
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.
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.
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.