VB6 RC5-CoreAudio-Demo-VBForums
Results 1 to 11 of 11

Thread: VB6 RC5-CoreAudio-Demo

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    3,195

    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 09:27 PM.

  2. #2
    Fanatic Member
    Join Date
    Apr 2012
    Posts
    904

    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
    Hyperactive Member
    Join Date
    Sep 2012
    Posts
    457

    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 09:14 AM.

  5. #5
    Fanatic Member
    Join Date
    Apr 2012
    Posts
    904

    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
    Hyperactive Member
    Join Date
    Sep 2012
    Posts
    457

    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
    Hyperactive Member
    Join Date
    Sep 2012
    Posts
    457

    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
    Hyperactive Member
    Join Date
    Sep 2012
    Posts
    457

    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
    Hyperactive Member
    Join Date
    Sep 2012
    Posts
    457

    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
    Join Date
    Oct 2013
    Posts
    2,910

    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
    Hyperactive Member
    Join Date
    Sep 2012
    Posts
    457

    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.

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

Survey posted by VBForums.