Results 1 to 16 of 16

Thread: VB6 RC5-CoreAudio-Demo

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    VB6 RC5-CoreAudio-Demo

    Here a small CoreAudio-Example, based on the appropriate abstraction-Classes of the RichClient.
    (as mentioned and requested in this thread): http://www.vbforums.com/showthread.p...ther-like-Game

    CoreAudio was introduced as the new (LowLevel) SoundAPI for Win-Versions from Vista onwards.

    It allows such things as "InApp-Session-VolumeControl, Soundbuffer-reading and -writing, Enumeration of
    Sound-Devices, Fine-Control over each of the channels of e.g. a "5+1" SoundCard etc...

    The Read-direction of CoreAudio-SoundBuffers I've already covered in this older example here:
    http://www.vbforums.com/showthread.p...and-onwards%29
    (visualizing the Buffer-Input, which comes in over: ...GetDefaultAudioEndpoint(eCapture, eCommunications) -> usually the microphone).

    This example here is focusing on demonstrating the handling of "InApp-SoundVolume/Muting" -
    and the SoundRendering of 4 smaller SoundBuffers (which reside as *.mp3 in the Apps \Res\-SubFolder).
    Here the Zip: CoreAudioDemo.zip

    With relatively low efforts, one could expand on this Demo, to e.g. implement a nice
    "Piano-Roll-like Sequencer" - or something alike (as seen in some Phone- or -Tablet-Apps, that cover
    simple "SoundLoop-Pattern-Mixers" which support live-changes of "correctly fitted" Sample-Loops).

    Here's a ScreenShot, what the Demo currently looks like:


    The 4 SoundSample-Player-Widgets to the right of the above Form can be:
    - in case of the Top-Widget, labelled 'SampleLoop' - switched On and Off permanently
    - and the lower three Sound-Widgets are in "Tap-Mode" (acting more like a little Drum-Kit)

    So you can Switch-On the TopMost Sound - it will be in repeat-mode by default -
    and then you can add sound by "tapping" the other three (if you keep the Mouse down,
    the 3 Tap-Widgets will repeat themselves in a timely fashion).

    So, whilst the right part of the above ScreenShot demonstrates the CoreAudio-SoundBuffer-Handling,
    the left part of the Screen (the rotating Knob-Widget) demonstrates the interaction with:
    - cSimpleAudioVolume (responsible for interaction with the InApp-SoundLevel and InApp-Muting)
    - cAudioMeterInformation (responsible for the Peak-Meter-Visualization at the bottom of the Knob).

    This InApp-AudioVolume-Handling works in a "two-way-fashion", since it is also present in
    the new WinSystem-Mixer-Dialogues:


    In the above ScreenShot, the focused Entry labeled "CoreAudioDemo" allows to
    control your InApp-SoundVolume/Muting as well - and should be properly reflected
    in the appropriate Control of your App, so that both GUI-interactions remain "synced"
    (the Knob reflecting the Settings of the System-Dialogue, and vice versa).



    The cSimpleAudioVolume-Class of the RC5 offers the needed Events for that kind of
    two-way interaction.

    But take a look at the code yourself, play around a bit - and just ask when something is not clear.

    Have fun!

    Olaf
    Last edited by Schmidt; May 17th, 2016 at 08:27 PM.

  2. #2
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: VB6 RC5-CoreAudio-Demo

    Much appreciated, Olaf. Checking it out now...
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  3. #3
    New Member
    Join Date
    Mar 2017
    Posts
    1

    Re: VB6 RC5-CoreAudio-Demo

    Is there a way to control the other app volumes, rather than just the current app ? I've had a look but can fathom it out or see any documentation.thank you.

  4. #4
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: VB6 RC5-CoreAudio-Demo

    When I tested the RC5-CoreAudio-Demo on Win10, everything was OK. But when I tested it on XP, there was an error message: Couldn't create DeviceEnumerator
    Attached Images Attached Images  
    Last edited by dreammanor; Sep 10th, 2017 at 08:14 AM.

  5. #5
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: VB6 RC5-CoreAudio-Demo

    CoreAudio is only available on Vista and upwards...
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  6. #6
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: VB6 RC5-CoreAudio-Demo

    Quote Originally Posted by ColinE66 View Post
    CoreAudio is only available on Vista and upwards...
    Oh, thank you for your reminder. I was so blind that I didn't see Olaf's instructions.

  7. #7
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: VB6 RC5-CoreAudio-Demo

    Hi Olaf,

    I tried to open a large mp3 file (8M) in the example of "VB6 RC5-CoreAudio-Demo", the program popped up an error message: Run-time error '6': Overflow

    Code:
    Public Property Get FrameIdxCurrent() As Double
      If ARC Is Nothing Then Exit Property
      FrameIdxCurrent = (FrameIdxToCopyFrom - ARC.CalcFrameCountAheadOfClientSrc + 1000 * 1# * FramesTotal) Mod FramesTotal
    End Property
    Note: FramesTotal = 21703680 at this point.

  8. #8
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: VB6 RC5-CoreAudio-Demo

    I don't quite understand the meaning of that red sentence (code line with error), I made some changes to avoid Overflow error. The program now opens a large Mp3 file without error. Maybe someone else has a better solution.

    Code:
    Public Property Get FrameIdxCurrent() As Double
        If ARC Is Nothing Then Exit Property
      
        '---------------------------------------------------------------------------------------------------------------------------------------------
        '--- To avoid overflow --- DreamManor Update on 24-11-2017 ---
        'FrameIdxCurrent = (FrameIdxToCopyFrom - ARC.CalcFrameCountAheadOfClientSrc + 1000 * 1# * FramesTotal) Mod FramesTotal
      
        Dim nIndex As Double
            
        nIndex = 1# * 1000 * FramesTotal
        nIndex = FrameIdxToCopyFrom - ARC.CalcFrameCountAheadOfClientSrc + nIndex
        
        If nIndex <= 2 ^ 31 - 1 Then
            FrameIdxCurrent = (FrameIdxToCopyFrom - ARC.CalcFrameCountAheadOfClientSrc + 1000 * FramesTotal) Mod FramesTotal
        Else
            nIndex = nIndex / FramesTotal
            nIndex = nIndex - Int(nIndex)
            If nIndex > 0 Then
                nIndex = nIndex * FramesTotal
            End If
            FrameIdxCurrent = nIndex
        End If
        '--------------------------------------------------------------------------------------------------------------------------------------------
        
    End Property
    Last edited by dreammanor; Nov 24th, 2017 at 11:43 AM.

  9. #9
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: VB6 RC5-CoreAudio-Demo

    Now there is another problem that needs Olaf's help.
    When I open an mp3 file(1.5M), the following error message appears:

    Code:
    Public Sub InitFromMP3(FileNameOrByteArray, RenderEndPoint As cMMDevice, ByVal PlayFreq As Long, Optional ByVal SkipLeadingSilence As Boolean)
    Dim Src() As Byte, Dst() As Long, DstBytesUsed As Long, msEstimated As Long
        Src = FileNameOrByteArray
        If VarType(FileNameOrByteArray) = vbString Then Src = New_c.FSO.ReadByteContent(CStr(FileNameOrByteArray))
        With New_c.MP3Resource
          .GetMP3Info Src, OrigFreq, Channels, ID3Offs, msEstimated
          ReDim Dst(0 To msEstimated / 1000 * OrigFreq * 1.5)
          .OpenConverter OrigFreq, Channels, 16
          .ConvertBuffer VarPtr(Src(ID3Offs)), UBound(Src) + 1 - ID3Offs, VarPtr(Dst(0)), 4 * (UBound(Dst) + 1), DstBytesUsed, True
        End With
        ReDim Preserve Dst(DstBytesUsed \ 4 - 1)
        InitWithFrames Dst, RenderEndPoint, PlayFreq, SkipLeadingSilence
    End Sub
    Attached Images Attached Images  

  10. #10
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: VB6 RC5-CoreAudio-Demo

    Then you need to figure out what's needed in the following code line:
    Code:
     ReDim Dst(0 To msEstimated / 1000 * OrigFreq * 1.5)
    Is the file compressed using VBR or a fixed bitrate?

  11. #11
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: VB6 RC5-CoreAudio-Demo

    Quote Originally Posted by Arnoutdv View Post
    Then you need to figure out what's needed in the following code line:
    Code:
     ReDim Dst(0 To msEstimated / 1000 * OrigFreq * 1.5)
    Is the file compressed using VBR or a fixed bitrate?
    Hi Arnoutdv, thanks for your reminder.

    I tracked the variable msEstimated, whose value is 38353 ms, but in TheTrick's software this value (duration-ms) is 39079 ms. This value is also greater than 39,000 in Audacity software. In other words, in the RC5.MP3Resource class, the audio files' playback time (estimated time) is less than other software. This causes the allocation capacity of the dst array is too small. I modified the following source code, now the program can play that mp3 file:

    Code:
     'ReDim Dst(0 To msEstimated / 1000 * OrigFreq * 1.5)
     ReDim Dst(0 To msEstimated / 1000 * OrigFreq * 3)
    I don't know what is the basis of multiplying 1.5 or multiplying 3 in the source code?

    In addition, vbForums doesn't allow uploading files over 500K, so I have no way to upload the test file.
    Last edited by dreammanor; Nov 28th, 2017 at 11:09 AM.

  12. #12
    Hyperactive Member
    Join Date
    Jul 2017
    Posts
    344

    Angry Re: VB6 RC5-CoreAudio-Demo

    As soon as I start the project "CoreAudioDemo", I get this error:

    Ungültiger Prozeduraufruf oder ungültiges Argument.
    (Invalid procedure call or invalid argument)

    Windows 10:

    Name:  error1.jpg
Views: 1093
Size:  24.4 KB

  13. #13

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 RC5-CoreAudio-Demo

    Quote Originally Posted by tmighty2 View Post
    As soon as I start the project "CoreAudioDemo", I get this error:

    Ungültiger Prozeduraufruf oder ungültiges Argument.
    (Invalid procedure call or invalid argument)
    Are you trying to use that (RC5-based) demo with RC6 by any chance?

    If yes, then "just switching the Project-Reference" is not enough for most older Demos.

    In many larger RC5-Demos, there's an additional need, to do a global search/replace on the Code:
    - searching for fully qualified Class-Types, which start with the term: [vbRichClient5.] <-- please notice the trailing dot ...
    - replacing it with either an empty String, or with a leading [RC6.] as the lib-name of the fully qualified Class-Type

    Olaf

  14. #14
    Addicted Member
    Join Date
    Feb 2022
    Posts
    167

    Re: VB6 RC5-CoreAudio-Demo

    Excellent work Olaf. It's also a great example of Cairo widgets.

    I feel like Sherlock Holmes researching RichClient, and a very pleasant discovery was the Unicode path function to supersede VB's anemic ANSI Dir function, or the various DirW routines floating around.

    Code:
    Dim DL As cDirList 
    Set DL = New_c.FSO.GetDirList(App.Path & "\Res", , "*.jpg;*.png")
    I see there is a cMP3Resource class in RC5 and RC6 with :

    Code:
    Function OpenConverter(DstFreq As Long, [DstChan As Long = 2], [DstBits As Long = 16], [DstFmtT As Long = 1]) As Boolean
    I assume this for conversion to .Wav ...? Are there any examples of how to use this?

    It would be overkill for converting an mp3 to DstBits As Long = 24, or 32 ---- but if it works, that would be nice for some audio editing software to do granular noise reduction.

    Cheers
    Last edited by taishan; Sep 1st, 2023 at 12:51 PM.

  15. #15

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 RC5-CoreAudio-Demo

    Quote Originally Posted by taishan View Post
    I see there is a cMP3Resource class in RC5 and RC6 with :

    Code:
    Function OpenConverter(DstFreq As Long, [DstChan As Long = 2], [DstBits As Long = 16], [DstFmtT As Long = 1]) As Boolean
    I assume this for conversion to .Wav ...? Are there any examples of how to use this?
    If I use google to find RC-Demos for a certain class...
    - I usually include the classname in DoubleQuotes
    - and prefix this search-term with site:vbForums.com

    E.g. in your case, it would look like: [ site:vbforums.com "cMP3Resource" ]
    Which spits out (among a handful of other related Links):
    https://www.vbforums.com/showthread....=1#post4936139

    Olaf

  16. #16
    Addicted Member
    Join Date
    Feb 2022
    Posts
    167

    Re: VB6 RC5-CoreAudio-Demo

    Quote Originally Posted by Schmidt View Post
    If I use google to find RC-Demos for a certain class...
    - I usually include the classname in DoubleQuotes
    - and prefix this search-term with site:vbForums.com

    E.g. in your case, it would look like: [ site:vbforums.com "cMP3Resource" ]
    Which spits out (among a handful of other related Links):
    https://www.vbforums.com/showthread....=1#post4936139

    Olaf
    Thank you for the google search hints! you are the man!

    btw, please don't let this documentation expire. Seems like a few examples worth keeping... plus, it is a cool website. Cheers
    Last edited by taishan; Sep 2nd, 2023 at 10:35 PM.

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