Results 1 to 10 of 10

Thread: DirectSound8 / ACM / WAVEFORMATEXTENSIBLE

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2014
    Posts
    1,051

    DirectSound8 / ACM / WAVEFORMATEXTENSIBLE

    Code:
    Private Type WAVEFORMATEXTENSIBLE
        Format As WAVEFORMATEX
        wValidBitsPerSample As Integer
        wSamplesPerBlock As Integer
        wReserved As Integer
        dwChannelMask As Long
        subFormat As Integer ' ??? As GUID
    End Type
    Im trying to understand this one. https://docs.microsoft.com/en-us/win...rmatextensible

    it should be used together with:

    Code:
    Private Type WAVEFORMATEX       ' // Audio format structure
        wFormatTag      As Integer ' // Audio type (WAVE/MP3/etc.)
        nChannels       As Integer ' // Number of channels (mono/stereo)
        nSamplesPerSec  As Long    ' // Sample rate
        nAvgBytesPerSec As Long    ' // Number of bytes per second
        nBlockAlign     As Integer ' // One block (all channels) align in bytes
        wBitsPerSample  As Integer ' // Number of bits per sample
        cbSize          As Integer ' // Number of extra bytes
    End Type
    .wFormatTag is WAVE_FORMAT_PCM or WAVE_FORMAT_EXTENSIBLE, the latter is used together with the WAVEFORMATEXTENSIBLE structure.

    subFormat as GUID, what do I do here? it seems that GUID is a integer, but Im not sure, the GUID should be KSDATAFORMAT_SUBTYPE_ADPCM
    and the waveformat should be: WAVE_FORMAT_ADPCM
    Im unsure what to do.

    what I want to do:
    - convert a mp3 to ADPCM, save it to a file (that I can do with ffmpeg or some other tool, but would be nice if I can do it from VB6 as well)
    - another vb6 program, I load this ADPCM file. I want to play it using directsound8 (http://www.vbforums.com/showthread.p...B6-DirectSound)
    - maybe I need to convert ADPCM to PCM, and I can use ACM (similar what we can do with mp3>pcm), but to do that it seems that I need this WAVEFORMATEXTENSIBLE

    question, anyone has ever done it?
    mp3 > pcm is already done by The trick in his DirectSound package, (look his thread)
    but mp3 > adpcm and adpcm > pcm need this WAVEFORMATEXTENSIBLE to work. but Im not sure what to do.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,072

    Re: DirectSound8 / ACM / WAVEFORMATEXTENSIBLE

    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2014
    Posts
    1,051

    Re: DirectSound8 / ACM / WAVEFORMATEXTENSIBLE

    I noticed that in The trick typelib theres both a WAVEFORMATEX and WAVEFORMATEXTENSIBLE structure.
    but, .wFormatTag is integer and .SubFormat is long

    looking around I found this:
    Private Const WAVE_FORMAT_EXTENSIBLE As Long = &HFFFE

    that need to be placed in .wFormatTag, but it will overflow.
    and .SubFormat is Long, and the GUI is like

    Code:
    KSDATAFORMAT_SUBTYPE_ADPCM
    GUID = ::GUID
    Data1: 2,
    Data2: 0,
    Data3: 16,
    Data4: [128, 0, 0, 170, 0, 56, 155, 113]

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,072

    Re: DirectSound8 / ACM / WAVEFORMATEXTENSIBLE

    Spending just a couple minutes googling, found a few threads showing that the subFormat member is indeed a GUID (16 byte structure).

    Edited. If you google freebasic.net along with WAVEFORMATEXTENSIBLE, you can find an example in freebasic. Think it's close enought for a sample...
    Code:
    dim as WAVEFORMATEXTENSIBLE WF
    WF.Format.wFormatTag      = &HFFFE ' WAVE_FORMAT_EXTENSIBLE
    WF.Format.nSamplesPerSec  = 44100
    WF.Format.nChannels       = 4
    WF.Format.wBitsPerSample  = 16
    WF.Format.nBlockAlign     = 8  ' bits\8 * channels
    WF.Format.nAvgBytesPerSec = 352800 ' 44100*8
    WF.Format.cbSize          = 22 ' sizeof(GUID)+sizeof(uinteger)+sizeof(ushort)
    WF.wValidBitsPerSample    = 16
    WF.dwChannelMask          = &H33 'SPEAKER_FRONT_LEFT  or SPEAKER_FRONT_RIGHT or SPEAKER_BACK_LEFT or SPEAKER_BACK_RIGHT
    WF.subFormat.Data1        = &H00000001
    WF.subFormat.Data2        = &H0000
    WF.subFormat.Data3        = &H0010
    WF.subFormat.Data4(0)     = &H80
    WF.subFormat.Data4(1)     = &H00
    WF.subFormat.Data4(2)     = &H00
    WF.subFormat.Data4(3)     = &HAA
    WF.subFormat.Data4(4)     = &H00
    WF.subFormat.Data4(5)     = &H38
    WF.subFormat.Data4(6)     = &H9B
    WF.subFormat.Data4(7)     = &H71
    Last edited by LaVolpe; May 13th, 2020 at 05:03 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2014
    Posts
    1,051

    Re: DirectSound8 / ACM / WAVEFORMATEXTENSIBLE

    it seems something is not working.

    the structures are:
    Code:
    Private Type subFormatGUID
        Data1 As Long
        Data2 As Integer
        Data3 As Integer
        Data4(7) As Byte
    End Type
    
    Private Type WAVEFORMATEXTENSIBLESamples
        wValidBitsPerSample As Integer
        wSamplesPerBlock As Integer
        wReserved As Integer
    End Type
        
    Public Type WAVEFORMATEX
        wFormatTag      As Integer
        nChannels       As Integer
        nSamplesPerSec  As Long
        nAvgBytesPerSec As Long
        nBlockAlign     As Integer
        wBitsPerSample  As Integer
        cbSize          As Integer
    End Type
    
    Private Type WAVEFORMATEXTENSIBLE
        Format As WAVEFORMATEX
        Samples As WAVEFORMATEXTENSIBLESamples
        dwChannelMask As Long
        subFormat As subFormatGUID
    End Type
    and I really try to be accurate. WORD=Integer, DWORD=Long, etc, even added "Samples", since that is in a "union".

    Code:
    Dim KSDATAFORMAT_SUBTYPE_ADPCM As subFormatGUID
        
        With KSDATAFORMAT_SUBTYPE_ADPCM
            .Data1 = 2
            .Data2 = 0
            .Data3 = 16
            .Data4(0) = 128
            .Data4(1) = 0
            .Data4(2) = 0
            .Data4(3) = 170
            .Data4(4) = 0
            .Data4(5) = 56
            .Data4(6) = 155
            .Data4(7) = 113
        End With
    this should be the GUID for FORMAT_SUBTYPE_ADPCM
    Code:
    With dstFormat
            .wBitsPerSample = 16
            .nChannels = Format.nChannels
            .nSamplesPerSec = Format.nSamplesPerSec
            .nBlockAlign = (.wBitsPerSample \ 8) * .nChannels
            .nAvgBytesPerSec = .nBlockAlign * .nSamplesPerSec
            .wFormatTag = &HFFFE
            .cbSize = Len(dFormat)
    End With
    With dFormat
            .Format = dstFormat
            .Samples.wReserved = 0
            .Samples.wSamplesPerBlock = dstFormat.wBitsPerSample
            .Samples.wValidBitsPerSample = 16
            .dwChannelMask = 0
            .subFormat = KSDATAFORMAT_SUBTYPE_ADPCM
    End With
    so instead of using dstFormat I use dFormat
    "Format" is for the mp3-structure, that works, since its the same I use when converting mp3>pcm.
    .cbSize I try different numbers, 22 and above, but without success.
    the same with .dwChannelMask, I try different alternatives, but nothing.

    Code:
    acmStreamOpen hStream, 0, Format, dFormat, ByVal 0&, ByVal 0&, ByVal 0&, 0
    but

    Code:
    acmStreamSize hStream, size, acmSize, ACM_STREAMSIZEF_SOURCE
    acmSize is 0


    can anyone see if theres a problem in the code?
    Last edited by baka; May 13th, 2020 at 07:18 PM.

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,072

    Re: DirectSound8 / ACM / WAVEFORMATEXTENSIBLE

    VB doesn't do unions in their structures
    Code:
    typedef struct {
      WAVEFORMATEX Format;
      union {
        WORD wValidBitsPerSample;
        WORD wSamplesPerBlock;
        WORD wReserved;
      } Samples;
      DWORD        dwChannelMask;
      GUID         SubFormat;
    } WAVEFORMATEXTENSIBLE, *PWAVEFORMATEXTENSIBLE;
    Would be more like this... Union = one of these, not all of these
    Code:
    typedef struct {
      WAVEFORMATEX Format;
      WORD         Samples; ' wValidBitsPerSample, wSamplesPerBlock, wReserved depending on scenario
      DWORD        dwChannelMask;
      GUID         SubFormat;
    } WAVEFORMATEXTENSIBLE, *PWAVEFORMATEXTENSIBLE;
    Based on the examples I've seen (all non-VB), the above in VB would look like this?
    Code:
    Private Type WAVEFORMATEXTENSIBLE
    '    Format As WAVEFORMATEX
        wFormatTag      As Integer
        nChannels       As Integer
        nSamplesPerSec  As Long
        nAvgBytesPerSec As Long
        nBlockAlign     As Integer
        wBitsPerSample  As Integer
        cbSize          As Integer
        Samples As Integer
        dwChannelMask As Long
        subFormat As subFormatGUID
    End Type
    Why did I include WAVEFORMATEX members directly into WAVEFORMATEXTENSIBLE? Padding.
    WAVEFORMATEX is not DWord aligned, has uneven number of Integer members. If we include it inside the larger WAVEFORMATEXTENSIBLE, VB will add padding. But if we include its members directly, now we have an even number of Integer members
    Last edited by LaVolpe; May 13th, 2020 at 07:42 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2014
    Posts
    1,051

    Re: DirectSound8 / ACM / WAVEFORMATEXTENSIBLE

    ok, I tried it, still returning 0

    I tried:

    Code:
    Private Type subFormatGUID
        Data1 As Long
        Data2 As Integer
        Data3 As Integer
        Data4(7) As Byte
    End Type
    
    Private Type WAVEFORMATEXTENSIBLE
        wFormatTag      As Integer
        nChannels       As Integer
        nSamplesPerSec  As Long
        nAvgBytesPerSec As Long
        nBlockAlign     As Integer
        wBitsPerSample  As Integer
        cbSize          As Integer
        Samples         As Integer
        dwChannelMask   As Long
        subFormat       As subFormatGUID
    End Type
    and also:

    Code:
    Private Type WAVEFORMATEXTENSIBLE
        wFormatTag      As Integer
        nChannels       As Integer
        nSamplesPerSec  As Long
        nAvgBytesPerSec As Long
        nBlockAlign     As Integer
        wBitsPerSample  As Integer
        cbSize          As Integer
        Samples         As Integer
        dwChannelMask   As Long
        Data1           As Long
        Data2           As Integer
        Data3           As Integer
        Data4(7)        As Byte
    End Type
    trying the freebasic.net parameters and the one I use, but both results AcmSize = 0

    Code:
    With dFormat
            .nChannels = 4 ' Format.nChannels
            .nSamplesPerSec = 44100 ' Format.nSamplesPerSec
            .wBitsPerSample = 16
            .nBlockAlign = 8 ' (.wBitsPerSample \ 8) * .nChannels
            .nAvgBytesPerSec = 352800 ' .nBlockAlign * .nSamplesPerSec
            .Samples = 0 '16
            .cbSize = Len(dFormat) ' 22+
            .dwChannelMask = &H33 ' 0 or 3
            .wFormatTag = &HFFFE
            .subFormat = KSDATAFORMAT_SUBTYPE_ADPCM
    end with
    acmStreamOpen hStream, 0, Format, dFormat, ByVal 0&, ByVal 0&, ByVal 0&, 0
    acmStreamSize hStream, size, AcmSize, ACM_STREAMSIZEF_SOURCE

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,072

    Re: DirectSound8 / ACM / WAVEFORMATEXTENSIBLE

    Well this is where I bow out. I am not familiar with the APIs you are using. The structure itself [LenB(dFormat)] should be 40 bytes from what I've looked at on the web. That's what I concentrated on. I would suggest to send Trick a PM and try to get some advice since he is one of the gurus on this site regarding your topic.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2014
    Posts
    1,051

    Re: DirectSound8 / ACM / WAVEFORMATEXTENSIBLE

    thx for the help!
    I will keep trying, but for now I take a break, let the brain rest.
    When I have more, I will post again!

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2014
    Posts
    1,051

    Re: DirectSound8 / ACM / WAVEFORMATEXTENSIBLE

    so today I tried this:
    https://docs.microsoft.com/en-us/pre...28v%3dvs.85%29
    and
    https://icculus.org/SDL_sound/downlo...n/wavecomp.htm

    Code:
    Private Type ADPCMCOEFSET
        iCoef1          As Long
        iCoef2          As Long
    End Type
    
    Private Type ADPCMWAVEFORMAT
        wFormatTag       As Integer
        nChannels        As Integer
        nSamplesPerSec   As Long
        nAvgBytesPerSec  As Long
        nBlockAlign      As Integer
        wBitsPerSample   As Integer
        cbSize           As Integer
        wSamplesPerBlock As Integer
        wNumCoef         As Integer
        aCoeff(1 To 7)   As ADPCMCOEFSET
    End Type
    Code:
    With dFormat
            .nChannels = Format.nChannels
            .nSamplesPerSec = Format.nSamplesPerSec
            .wBitsPerSample = 4
            .nBlockAlign = 32 * .wBitsPerSample * .nChannels
            .wNumCoef = 7
            .aCoeff(1).iCoef1 = 256
            .aCoeff(2).iCoef1 = 512
            .aCoeff(2).iCoef2 = -256
            .aCoeff(4).iCoef1 = 192
            .aCoeff(4).iCoef2 = 64
            .aCoeff(5).iCoef1 = 240
            .aCoeff(6).iCoef1 = 460
            .aCoeff(6).iCoef2 = -208
            .aCoeff(7).iCoef1 = 392
            .aCoeff(7).iCoef2 = -232
            .wSamplesPerBlock = (.nBlockAlign * 2) \ .nChannels - 12
            .nAvgBytesPerSec = ((.nSamplesPerSec \ .wSamplesPerBlock) * .nBlockAlign)
            .wFormatTag = WAVE_FORMAT_ADPCM
            .cbSize = LenB(dFormat)
    End With
    .nBlockAlign did have a (N+1) * .wBitsPerSample * .nChannels formula, but not sure what N is.
    I know that .wSamplesPerBlock need to be between 32-512 so I experimented N, using different values.
    even so, the same result, AcmStream will not work.
    so I suspect this is the wrong approach yet again.

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