sound and speech recording api, etc. - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

sound and speech recording api, etc.

Greetings,

I am beginning to design a program that will record audio from the microphone or line-in, and save the recordings in files.
One of the prominent features of the program will be that it will run constantly in the background and start recording when receiving a signal above a certain threshold. I have a few preliminary technical questions I hope someone can answer (partial answers are also welcome):

1. Which SDK/API should I use for recording? The best options I came across seem to be (i) the Windows multimedia API, (ii) DirectSound, and (iii) the Total Recorder Developer Edition or their Virtual Sound Driver SDK. Other possibilities I came across are OpenAL, Allegro and SDL. What are their differences and relative advantages and disadvantages? Are there better ones?

These are the criteria that concern me:
(i) stability, given that recording will be continuous for long periods of time,
(ii) compatibility with all versions of Windows,
(iii) ease of use and lack of bugs,
(iv) useful and varied advanced features,
(v) low latency,
(vi) good integration with MinGW (preferably through Dev-Cpp),
(vii) availability of examples and good documentation (if you have links to examples of the api you recommend, that would be nice).
If you have suggestions for other obvious criteria I am missing, please tell me; specifically, are there any special considerations to take when recording continuously for a long time, or when the program needs to run flawlessly on all versions of Windows?

2. Does recording or playing back in the background involve multi-threading (or rather, will I have to take care of it or will the SDK I will use do it)?

3. The program is intended to record speech. I have a few questions about codecs: (i) Is there any reason to use or not to use the codecs that come with Windows (given, for example, the availability of Speex)? (ii) If I use just one codec, is there another codec that may be a better choice than Speex (for example, if I want users to be able to play their files on any computer, or for other reasons)? (iii) As to patented codecs, who needs to pay for their use? The software makers/distributors or the users? Does the payment need to be payed once or per copy? Where can this information can be found, and also information about which codecs are restricted for use and which aren't?

4. Are there any good (and preferably open-source) libraries for reducing noise and echo, or similar useful functions?

Thanks,
Bob

«1

Comments

  • JonathanJonathan Posts: 2,914Member
    : I am beginning to design a program that will record audio from the microphone or line-in, and save the recordings in files.
    : One of the prominent features of the program will be that it will run constantly in the background and start recording when receiving a signal above a certain threshold. I have a few preliminary technical questions I hope someone can answer (partial answers are also welcome):
    :
    : 1. Which SDK/API should I use for recording? The best options I came across seem to be (i) the Windows multimedia API, (ii) DirectSound, and (iii) the Total Recorder Developer Edition or their Virtual Sound Driver SDK. Other possibilities I came across are OpenAL, Allegro and SDL. What are their differences and relative advantages and disadvantages? Are there better ones?
    :
    I'll answer by criteria.

    : These are the criteria that concern me:
    : (i) stability, given that recording will be continuous for long
    : periods of time,
    The classic issue you may run into on this front are things related to storing more than 4 GB of wave data (2^32 bytes = maybe 6 hours of recording, e.g. 2^32 / (4 * 44100). I'm not sure you'll have this for input, but rather when writing the data to the files.

    : (ii) compatibility with all versions of Windows,
    Win32 API is most compatible, or at least since 9x. DirectX requires the DirectX SDK to be installed.

    : (iii) ease of use and lack of bugs,
    Win32 API is pretty easy to use. DirectX is probably OK once you learn it. Can't speak for the others.

    : (iv) useful and varied advanced features,
    Win32 API is fairly low level. DirectX (and probably the others) would provide more in the way of features.

    : (v) low latency,
    For this I'm pretty certain that DirectX beats Win32 API.

    : (vi) good integration with MinGW (preferably through Dev-Cpp),
    Don't know about that.

    : (vii) availability of examples and good documentation (if you have links to examples of the api you recommend, that would be nice).
    :
    I implemented audio output using waveOut Win32 APIs just by looking at the MSDN.

    : If you have suggestions for other obvious criteria I am missing,
    : please tell me; specifically, are there any special considerations
    : to take when recording continuously for a long time, or when the
    : program needs to run flawlessly on all versions of Windows?
    :
    Only the length issues related to the size of native ints. Its hard to guess where they will manifest themselves.

    : 2. Does recording or playing back in the background involve multi-threading (or rather, will I have to take care of it or will the SDK I will use do it)?
    :
    Depends on what your app is doing aside from the recording. I haven't used mutli-threading in my audio engine, but then it only ever does mix audio, so there's nothing that needs it.

    : 3. The program is intended to record speech. I have a few questions about codecs: (i) Is there any reason to use or not to use the codecs that come with Windows (given, for example, the availability of Speex)? (ii) If I use just one codec, is there another codec that may be a better choice than Speex (for example, if I want users to be able to play their files on any computer, or for other reasons)? (iii) As to patented codecs, who needs to pay for their use? The software makers/distributors or the users? Does the payment need to be payed once or per copy? Where can this information can be found, and also information about which codecs are restricted for use and which aren't?
    :
    Ah, so you want to compress it... I'd look to using ones in common use. I'm not familiar with Speex. MP3 has some restrictions, I'm not sure on the exact details but there are some tenuous legal issues around it. OGG is completely open, so far as I'm aware. But this isn't a standard one with Windows. What you can use varies by codec I'd imagine, so I'm afraid you'll have to do your research there.

    : 4. Are there any good (and preferably open-source) libraries for reducing noise and echo, or similar useful functions?
    :
    AMaMP (my open source, cross-platform) audio engine will be getting effects etc pretty soon, but not for a little while. But if you need to see examples of implementations of these, or algorithms, I can point you in the right direction, or give you (VB...ugh) code. In fact, you can do a CVS checkout of the frontends for AMaMP. Hey, why not get the core while you're at it and join the implementation fun? Just kidding...well, not stopping you either. ;-)
    http://amamp.sourceforge.net/

    Hope this helps,

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • cbodapaticbodapati Posts: 65Member
    hai bob
    are you frequency conscious while recording.i.e., you want to record only the specified Band of frequencies(checked in real time) or only the time-domain threshold.
    I think rest is handled by Mr.Jonathan to fullfill your needs.

    Best Regards
    srikanth

  • TomyTomy Posts: 35Member
    hi

    some ideas:

    The goal is to create a program that works as an 'audio-scratchbook' ? If this is right, you could make some compromises on quality: 16 bit, 22050 kHz, mono could be enough.

    for the noise reduction: I suggest you program a dedicated gate... Maybe you could use the same code to detect the signal and gate it to reduce noise. Adding a reasonable attack time (only to prevent clicking), a minimum hold time, and a smooth release could do the trick.

    For the latency: since you do not ' monitor' the signal, this can't be an issue. In fact, you could choose a bigger latency of about 5 seconds or more. This allows you to predict some future incoming signals, preventing writing different files. Since you don't need to write all the information on disk, you could create a new file each time the gate opens; stopping whgen it closes again giving no future signal in the near future

    And my SDK rec: use DirectSound: it uses more hardware-resources than the standart API, works fine in background and is compatible with all windows since 98...

    greetings
    tom

    : Greetings,
    :
    : I am beginning to design a program that will record audio from the microphone or line-in, and save the recordings in files.
    : One of the prominent features of the program will be that it will run constantly in the background and start recording when receiving a signal above a certain threshold. I have a few preliminary technical questions I hope someone can answer (partial answers are also welcome):
    :
    : 1. Which SDK/API should I use for recording? The best options I came across seem to be (i) the Windows multimedia API, (ii) DirectSound, and (iii) the Total Recorder Developer Edition or their Virtual Sound Driver SDK. Other possibilities I came across are OpenAL, Allegro and SDL. What are their differences and relative advantages and disadvantages? Are there better ones?
    :
    : These are the criteria that concern me:
    : (i) stability, given that recording will be continuous for long periods of time,
    : (ii) compatibility with all versions of Windows,
    : (iii) ease of use and lack of bugs,
    : (iv) useful and varied advanced features,
    : (v) low latency,
    : (vi) good integration with MinGW (preferably through Dev-Cpp),
    : (vii) availability of examples and good documentation (if you have links to examples of the api you recommend, that would be nice).
    : If you have suggestions for other obvious criteria I am missing, please tell me; specifically, are there any special considerations to take when recording continuously for a long time, or when the program needs to run flawlessly on all versions of Windows?
    :
    : 2. Does recording or playing back in the background involve multi-threading (or rather, will I have to take care of it or will the SDK I will use do it)?
    :
    : 3. The program is intended to record speech. I have a few questions about codecs: (i) Is there any reason to use or not to use the codecs that come with Windows (given, for example, the availability of Speex)? (ii) If I use just one codec, is there another codec that may be a better choice than Speex (for example, if I want users to be able to play their files on any computer, or for other reasons)? (iii) As to patented codecs, who needs to pay for their use? The software makers/distributors or the users? Does the payment need to be payed once or per copy? Where can this information can be found, and also information about which codecs are restricted for use and which aren't?
    :
    : 4. Are there any good (and preferably open-source) libraries for reducing noise and echo, or similar useful functions?
    :
    : Thanks,
    : Bob
    :
    :

  • hyperbobhyperbob Posts: 6Member
    Thanks a lot Jonathan,

    I have some more questions about what you wrote:

    1. How do you suggest to overcome big file problem? I don't mind splitting the recordings into two or more parts (since the plan is to have the user access them only through my program), but how hard would the win32 api (or DirectX) make it for me?

    2. What exactly does DirectX require to be installed at the user's computer, and can my program install it for the user?

    3. Is there a toolkit that does not require me to do the multi-threading manually? I don't have much experience with multi-tasking and I want to avoid unexpected time-consuming schedule-upsetting bugs.

    4. Why do you recommend using a common or standard codec? Is it just so that people will be able to play the files via media player, etc., or on other computers? For me it is more important that the size of the files will be as small as possible without losing too much quality (since the program will probably be used to record and store a lot of audio), and of course to avoid paying royalties or whatever. The user will be able to access and play the files through my program, and if he wishes to use them in other contexts I don't mind converting them upon request. Does this change your recommendation?

    5. As to AMaMP, I'll be glad to make use of it when it has the features I need, but have almost no knowledge about audio programming so I don't think you would want me on the development team... (-;. In the meantime, I'll be happy to be pointed in the direction of examples of implementation or algorithms of echo and noise-reductions, etc.

    Thanks,

    Bob
  • hyperbobhyperbob Posts: 6Member
    Hi,

    : hai bob
    : are you frequency conscious while recording.i.e., you want to record only the specified Band of frequencies(checked in real time) or only the time-domain threshold.
    : I think rest is handled by Mr.Jonathan to fullfill your needs.

    I don't know. I may want to be frequency concious to remove noise. I don't know what it means to record only the time-domain threshold :-].
    Why?

    Thanks,

    Bob
  • hyperbobhyperbob Posts: 6Member
    Thanks Tommy,

    : for the noise reduction: I suggest you program a dedicated gate... Maybe you could use the same code to detect the signal and gate it to reduce noise. Adding a reasonable attack time (only to prevent clicking), a minimum hold time, and a smooth release could do the trick.

    I don't know what you mean by programming a dedicated gate. Is this DirectSound terminology? What is hold time and what do you mean by smooth release (or rather, how do these things become a noise reduction filter)?

    : For the latency: since you do not ' monitor' the signal, this can't be an issue. In fact, you could choose a bigger latency of about 5 seconds or more. This allows you to predict some future incoming signals, preventing writing different files. Since you don't need to write all the information on disk, you could create a new file each time the gate opens; stopping whgen it closes again giving no future signal in the near future

    Why do you say that I don't 'montior' the signal? I thought that's what I wanted to do...
    How does using a bigger latency allow me to do anything? I thought that latency in this case is the time difference between the time the signal gets in the computer and the time it gets to my program, no? Without the signal I can't do anything and I don't understand how waiting for it for a longer time benefits me in any way.

    : And my SDK rec: use DirectSound: it uses more hardware-resources than the standart API, works fine in background and is compatible with all windows since 98...

    Most people I spoke to said that DirectSound is less easy to use than the win32 api (I'm not sure if they meant it is more hard to learn or more easy to misuse or has bugs). What do you think about this?
    Why should it matter to me that it uses more hardware resources? Does DirectSound do the multi-threading for me when working in the background?

    Hmm... It turns out I didn't really understand most of what you said. Sorry :-]

    Thanks,

    Bob.
  • JonathanJonathan Posts: 2,914Member
    : Thanks a lot Jonathan,
    :
    : I have some more questions about what you wrote:
    :
    : 1. How do you suggest to overcome big file problem? I don't mind
    : splitting the recordings into two or more parts (since the plan is
    : to have the user access them only through my program), but how hard
    : would the win32 api (or DirectX) make it for me?
    :
    Sorry if I was unclear - I was more talking about writing the files to disk at that point although if the Win32 API or DirectX uses some kind of offset from 0 in terms of bytes you'll hit some fun. There is a maximum file size limit of 2 GB of FAT32. NTFS should be able to handle bigger files. But the problems all start to appear once you hit quantities measured above the magic value of 2^32 - 1, or in some cases 2^31 - 1. Of course, if your encoding then the file size issue most likely won't plague you. Just think about stuff inside your program.

    : 2. What exactly does DirectX require to be installed at the user's
    : computer, and can my program install it for the user?
    :
    You just need to point them to the DirectX setup which they can get from the MS site. Or you can include it, if you're shipping the product on a CD. DirectX, as far as I'm aware, is included with the latest versions of Windows anyway. 2000 onwards at leats.

    : 3. Is there a toolkit that does not require me to do the multi-
    : threading manually? I don't have much experience with multi-tasking
    : and I want to avoid unexpected time-consuming schedule-upsetting
    : bugs.
    :
    Nope, I'm not too happy on the multi-threading front either. They say it's all OK until you start sharing data between threads. When you do that you have to start woryying about locking, and when you have to worry about locking you have to worry about race conditions, etc... You may be able to get away with it all - certainly you can use DirectX or Win32 API from VB and you literally can't use threading there.

    : 4. Why do you recommend using a common or standard codec?
    I'm of the opinion that open standards are the way to go. This is one of the biggest problems with interoperation with MS software - closed standards etc. You don't have to share my opinion, of course.

    : Is it just so that people will be able to play the files via media
    : player, etc., or on other computers?
    This is certainly a big reason, yes.

    : For me it is more important that the size of the files will be as
    : small as possible without losing too much quality (since the program
    : will probably be used to record and store a lot of audio), and of
    : course to avoid paying royalties or whatever.
    Well, OGG, MP3 and WMA are the most popular ones and they all offer good quality and compression (all taking no more than 1/10 of the amount of space for a wave file for equivalent quality). As for IP stuff, WMA is Microsoft's format, take from that what you will. MP3 has patent issues around it. OGG Vorbis, on the other hand, is open and patent issue free. It claims to be better than MP3 on the quality for a given file size. See:-
    http://www.vorbis.com/

    : The user will be able to access and play the files through my
    : program, and if he wishes to use them in other contexts I don't mind
    : converting them upon request. Does this change your recommendation?
    I'd still like to be convinced that the codecs that are in popular use are a lot worse than the ones you're looking at. Given you want to be in the clear with loyalties etc, I would suggest you consider OGG, even if you don't finish up using it.

    : 5. As to AMaMP, I'll be glad to make use of it when it has the
    : features I need, but have almost no knowledge about audio
    : programming so I don't think you would want me on the development
    : team... (-;. In the meantime, I'll be happy to be pointed in the
    : direction of examples of implementation or algorithms of echo and
    : noise-reductions, etc.
    :
    I was thinking, just for interest (e.g. ignore this if you want), of how the AMaMP engine would provide for your needs (note that the things you'd need are far from being implemented). It'd be along the lines of:-

    1) Invoke AMaMP, giving it an instruction file stating:-
    An input from the soundcard by the SteamInput chunk
    An Effect chunk for a noise gate, giving it parameters to provide notifications over IPC when it opens/closes.
    A Placement chunk placed at the start of time with the input from the soundcard, no output and routing it via the noise gate effect.

    2) In your app, wait for an AMaMP message to be recieved when the noise gate opens.

    3) Send a message to the AMaMP engine to create an output and tell it to start routing data from the placement to that output.

    4) Wait for the noise gate to close again, get the notification, and remove the output.

    5) Back to 3.

    Well, that'd be fairly neat to do, but sadly just too much of AMaMP is incomplete to even contemplate being able to do any of that just yet. Effects support should be started in the next month or so, but this is what I do in my free time and it's somewhat lacking right now.

    Algorithm wise, the VB front end contains two classes of interest, one which implements a noise gate and the other which implements a multi-tap delay (echo). I would *not* recommend implementing these things in VB - other than the cross-platform capability AMaMP now has C allows me to give it high performance.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • JonathanJonathan Posts: 2,914Member
    : If I use just one codec, is there another codec that may be a better
    : choice than Speex (for example, if I want users to be able to play
    : their files on any computer, or for other reasons)? (iii) As to
    : patented codecs, who needs to pay for their use?
    I just checked Speex out of curiosity, and found that it, like OGG, is an open standard free of patent issues.

    http://www.speex.org/

    So it's an open standard, which is good, though like I said availability is not quite so hot.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • TomyTomy Posts: 35Member
    hi

    I guess i used a little to much 'sound engineering' terms, so I'll eplain different:

    :I don't know what you mean by programming a dedicated gate. Is this DirectSound terminology? What is hold time and what do you mean by smooth release (or rather, how do these things become a noise reduction filter)?

    A gate acts like a 'mute': it shuts down a source when the level of it is beyond a certain point. So if there is noise, you could set the decision level a fraction bove it, but far beyond the level of the message. Example: imagine 'noizzzzzzzMESSAGEnoizzzzzzz' coming into your program, the gate could make it ' MESSAGE '. The interesting thing is that the gate knows where the MESSAGE is, so you do not have to write a second function for detecting it. The side-effect if a gate is that it clicks when opening or shutting down; so you have to make a 'ramp' between closed and opened. Usualy the opening time is very short (<1ms) to prevent loss of information, but the closing time can be longer, to have a more natural sound.

    pseudo code for gate

    a = 0 //between 0 and 1

    level = (in * in * 0.1) + level * 0.9 // to smoothen it a little bit
    if level > desisionlevel // gate is open
    a = a + (1 - a) * 0.01 // 0.01 determines the attack time

    else
    a = a - a * 0.0001 // determines the release, experiment with it

    out = in * a

    you could suppose that if a < 0.01 there is no message

    : Why do you say that I don't 'montior' the signal? I thought that's what I wanted to do...
    : How does using a bigger latency allow me to do anything? I thought that latency in this case is the time difference between the time the signal gets in the computer and the time it gets to my program, no? Without the signal I can't do anything and I don't understand how waiting for it for a longer time benefits me in any way.
    By 'monitoring' I ment listening to it. Low latency is important when you want sounds to be heard in time with unexpected events. In your situantion, there is no need for low latency: if your program processes the signals like with 1 second delay, nobody will know or care, and it does not influence the stability or whatsoever...
    :
    : : And my SDK rec: use DirectSound: it uses more hardware-resources than the standart API, works fine in background and is compatible with all windows since 98...
    :
    : Most people I spoke to said that DirectSound is less easy to use than the win32 api (I'm not sure if they meant it is more hard to learn or more easy to misuse or has bugs). What do you think about this?
    : Why should it matter to me that it uses more hardware resources? Does DirectSound do the multi-threading for me when working in the background?

    accessing your line in trough directsound is a little less documented, but not more complicated or longer to implement as trough the standartd API... But you get better hardware-support...
    :
    : Hmm... It turns out I didn't really understand most of what you said. Sorry :-]
    :
    : Thanks,
    :
    : Bob.
    :

  • JonathanJonathan Posts: 2,914Member
    : pseudo code for gate
    :
    : a = 0 //between 0 and 1
    :
    : level = (in * in * 0.1) + level * 0.9 // to smoothen it a little bit
    : if level > desisionlevel // gate is open
    : a = a + (1 - a) * 0.01 // 0.01 determines the attack time
    :
    : else
    : a = a - a * 0.0001 // determines the release, experiment with it
    :
    : out = in * a
    :
    : you could suppose that if a < 0.01 there is no message
    :
    An inefficient VB class that implements a gate...

    [code]' ************************************************************************
    ' AMaMP
    ' Copyright Jonathan Worthington 2002,2003
    ' ************************************************************************
    ' This file is part of AMaMP.
    '
    ' AMaMP is free software; you can redistribute it and/or modify
    ' it under the terms of the GNU General Public License as published by
    ' the Free Software Foundation; either version 2 of the License, or
    ' (at your option) any later version.
    '
    ' This program is distributed in the hope that it will be useful,
    ' but WITHOUT ANY WARRANTY; without even the implied warranty of
    ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    ' GNU General Public License for more details.
    '
    ' You should have received a copy of the GNU General Public License
    ' along with this program; if not, write to the Free Software
    ' Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    ' ************************************************************************

    ' *******************************************************
    ' AMaMP :: NOISE GATE CLASS
    ' ^^^^^^^^^^^^^^^^^^^^^^^^^
    ' Re-usable class module that defines the noise gate
    ' object to allow noise gating to be applied.
    ' *******************************************************

    Option Explicit

    'Implement generic effect interface
    Implements clsGenericEffect

    'Local variable(s) to hold property value(s)
    Private mvarHoldTime As Integer 'local copy
    Private mvarAttackRate As Integer 'local copy
    Private mvarReleaseRate As Integer 'local copy
    Private mvarThreshold As Integer 'local copy

    'Other local variables.
    Private VolumeConstant As Double
    Private ReleaseConstant As Double
    Private AttackConstant As Double
    Private HoldTimeS As Double
    Private ThresholdConstant As Integer
    Private State As Byte
    Private StateTime As Double
    Private Prepared As Boolean
    Private SampleRate As Long

    'Set up state constants.
    Private Const STATE_OPEN = 0 'Completely open.
    Private Const STATE_CLOSING = 1 'Waiting to close for HoldTime.
    Private Const STATE_CLOSED = 2 'Attacking or closed.
    Private Const STATE_OPENING = 3 'Releasing or open.

    Private Property Get clsGenericEffect_FriendlyName() As String
    clsGenericEffect_FriendlyName = "Noise Gate"
    End Property
    Public Function clsGenericEffect_GetParameters() As Boolean
    'Create an instance of the noise gat settings form and
    'show it modally.
    Dim NSF As frmNoiseGate
    Set NSF = New frmNoiseGate
    NSF.Show 1

    If NSF.Cancelled Then
    'Cancelled. Return false.
    clsGenericEffect_GetParameters = False
    Else
    'Get values selected on form.
    mvarHoldTime = CInt(Val(NSF.txtHoldTime.Text))
    mvarAttackRate = CInt(Val(NSF.txtAttackRate.Text))
    mvarReleaseRate = CInt(Val(NSF.txtReleaseRate.Text))
    mvarThreshold = CInt(Val(NSF.txtThreshold.Text))
    clsGenericEffect_GetParameters = True
    End If

    'Destroy form object.
    Unload NSF
    Set NSF = Nothing
    End Function

    Public Function clsGenericEffect_Prepare() As Boolean
    'Check that we have a hold time, attack rate and release rate.
    If mvarHoldTime > 0 And mvarAttackRate > 0 And mvarReleaseRate > 0 Then
    'Set up constants.
    VolumeConstant = 1
    ReleaseConstant = 100 / mvarReleaseRate
    AttackConstant = mvarAttackRate / 100
    HoldTimeS = mvarHoldTime / 1000
    ThresholdConstant = Int((mvarThreshold / 100) * 44100)
    SampleRate = 44100

    'Set gate state details.
    State = 0
    StateTime = 0

    'Say that the prep was successful.
    clsGenericEffect_Prepare = True
    Prepared = True
    Else
    clsGenericEffect_Prepare = False
    Prepared = False
    End If
    End Function

    Public Sub clsGenericEffect_ProccessChunk(ByRef LeftSample As Integer, ByRef RightSample As Integer)
    'Dimension any variables.
    Dim SampleAverage As Integer

    'So long as we are prepared...
    If Prepared Then
    'Get the average of the samples to work with.
    If RightSample > 0 Then
    SampleAverage = Int((LeftSample + RightSample) / 2)
    Else
    SampleAverage = LeftSample
    End If

    'Decide what to do.
    Select Case State
    Case STATE_OPEN
    'See if we need to close.
    If Abs(SampleAverage) <= ThresholdConstant Then
    State = STATE_CLOSING
    StateTime = 0
    End If
    Case STATE_CLOSING
    'Check if threshold has been breached.
    If Abs(SampleAverage) > ThresholdConstant Then
    State = STATE_OPEN
    StateTime = 0
    End If

    'Check if we have reached the hold time.
    If StateTime >= HoldTimeS Then
    'If so, close.
    State = STATE_CLOSED
    StateTime = 0
    End If
    Case STATE_CLOSED
    'Check if we need to leave the state.
    If Abs(SampleAverage) > ThresholdConstant Then
    State = STATE_OPENING
    VolumeConstant = 0.000001
    StateTime = 0
    Else
    'Calculate new volume constant and apply it.
    VolumeConstant = VolumeConstant * AttackConstant
    LeftSample = Int(LeftSample * VolumeConstant)
    RightSample = Int(RightSample * VolumeConstant)
    End If
    Case STATE_OPENING
    'Check if we need to leave the state.
    If VolumeConstant >= 1 Then
    VolumeConstant = 1
    State = STATE_OPEN
    StateTime = 0
    Else
    'Calculate new volume constant and apply it.
    VolumeConstant = VolumeConstant * ReleaseConstant
    LeftSample = Int(LeftSample * VolumeConstant)
    RightSample = Int(RightSample * VolumeConstant)
    End If
    End Select

    'Increment state time.
    StateTime = StateTime + (1 / SampleRate)
    End If
    End Sub

    Public Property Let ReleaseRate(ByVal vData As Integer)
    'used when assigning a value to the property, on the left side of an assignment.
    'Syntax: X.ReleaseRate = 5
    mvarReleaseRate = vData
    End Property

    Public Property Get ReleaseRate() As Integer
    'used when retrieving value of a property, on the right side of an assignment.
    'Syntax: Debug.Print X.ReleaseRate
    ReleaseRate = mvarReleaseRate
    End Property

    Public Property Let AttackRate(ByVal vData As Integer)
    'used when assigning a value to the property, on the left side of an assignment.
    'Syntax: X.AttackRate = 5
    mvarAttackRate = vData
    End Property

    Public Property Get AttackRate() As Integer
    'used when retrieving value of a property, on the right side of an assignment.
    'Syntax: Debug.Print X.AttackRate
    AttackRate = mvarAttackRate
    End Property

    Public Property Let HoldTime(ByVal vData As Integer)
    'used when assigning a value to the property, on the left side of an assignment.
    'Syntax: X.HoldTime = 5
    mvarHoldTime = vData
    End Property

    Public Property Get HoldTime() As Integer
    'used when retrieving value of a property, on the right side of an assignment.
    'Syntax: Debug.Print X.HoldTime
    HoldTime = mvarHoldTime
    End Property

    Public Property Let Threshold(ByVal vData As Integer)
    'used when assigning a value to the property, on the left side of an assignment.
    'Syntax: X.HoldTime = 5
    mvarThreshold = vData
    End Property

    Public Property Get Threshold() As Integer
    'used when retrieving value of a property, on the right side of an assignment.
    'Syntax: Debug.Print X.HoldTime
    Threshold = mvarThreshold
    End Property

    Private Sub Class_Initialize()
    Prepared = False
    End Sub
    [/code]

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

«1
Sign In or Register to comment.