ホーム › Media.Multimedia › ADPCMWAVEFORMAT
ADPCMWAVEFORMAT
構造体サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。
フィールド
| フィールド | 型 | サイズ | x64 | x86 | 説明 |
|---|---|---|---|---|---|
| wfx | WAVEFORMATEX | 18 | +0 | +0 | 基本となる波形フォーマットを示すWAVEFORMATEX。 |
| wSamplesPerBlock | WORD | 2 | +18 | +18 | 1ブロックあたりのサンプル数。 |
| wNumCoef | WORD | 2 | +20 | +20 | 係数セットの数。 |
| aCoef | ADPCMCOEFSET | 4 | +22 | +22 | 予測係数セットの配列(ADPCMCOEFSET)。可変長配列の先頭。 |
各言語での定義
#include <windows.h>
// WAVEFORMATEX (x64 18 / x86 18 バイト)
#pragma pack(push, 1)
typedef struct WAVEFORMATEX {
WORD wFormatTag;
WORD nChannels;
DWORD nSamplesPerSec;
DWORD nAvgBytesPerSec;
WORD nBlockAlign;
WORD wBitsPerSample;
WORD cbSize;
} WAVEFORMATEX;
#pragma pack(pop)
// ADPCMCOEFSET (x64 4 / x86 4 バイト)
#pragma pack(push, 1)
typedef struct ADPCMCOEFSET {
SHORT iCoef1;
SHORT iCoef2;
} ADPCMCOEFSET;
#pragma pack(pop)
// ADPCMWAVEFORMAT (x64 26 / x86 26 バイト)
#pragma pack(push, 1)
typedef struct ADPCMWAVEFORMAT {
WAVEFORMATEX wfx;
WORD wSamplesPerBlock;
WORD wNumCoef;
ADPCMCOEFSET aCoef[1];
} ADPCMWAVEFORMAT;
#pragma pack(pop)using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct WAVEFORMATEX
{
public ushort wFormatTag;
public ushort nChannels;
public uint nSamplesPerSec;
public uint nAvgBytesPerSec;
public ushort nBlockAlign;
public ushort wBitsPerSample;
public ushort cbSize;
}
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct ADPCMCOEFSET
{
public short iCoef1;
public short iCoef2;
}
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct ADPCMWAVEFORMAT
{
public WAVEFORMATEX wfx;
public ushort wSamplesPerBlock;
public ushort wNumCoef;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public ADPCMCOEFSET[] aCoef;
}Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure WAVEFORMATEX
Public wFormatTag As UShort
Public nChannels As UShort
Public nSamplesPerSec As UInteger
Public nAvgBytesPerSec As UInteger
Public nBlockAlign As UShort
Public wBitsPerSample As UShort
Public cbSize As UShort
End Structure
<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure ADPCMCOEFSET
Public iCoef1 As Short
Public iCoef2 As Short
End Structure
<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure ADPCMWAVEFORMAT
Public wfx As WAVEFORMATEX
Public wSamplesPerBlock As UShort
Public wNumCoef As UShort
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=1)> Public aCoef() As ADPCMCOEFSET
End Structureimport ctypes
from ctypes import wintypes
class WAVEFORMATEX(ctypes.Structure):
_pack_ = 1
_fields_ = [
("wFormatTag", ctypes.c_ushort),
("nChannels", ctypes.c_ushort),
("nSamplesPerSec", wintypes.DWORD),
("nAvgBytesPerSec", wintypes.DWORD),
("nBlockAlign", ctypes.c_ushort),
("wBitsPerSample", ctypes.c_ushort),
("cbSize", ctypes.c_ushort),
]
class ADPCMCOEFSET(ctypes.Structure):
_pack_ = 1
_fields_ = [
("iCoef1", ctypes.c_short),
("iCoef2", ctypes.c_short),
]
class ADPCMWAVEFORMAT(ctypes.Structure):
_pack_ = 1
_fields_ = [
("wfx", WAVEFORMATEX),
("wSamplesPerBlock", ctypes.c_ushort),
("wNumCoef", ctypes.c_ushort),
("aCoef", ADPCMCOEFSET * 1),
]#[repr(C, packed(1))]
pub struct WAVEFORMATEX {
pub wFormatTag: u16,
pub nChannels: u16,
pub nSamplesPerSec: u32,
pub nAvgBytesPerSec: u32,
pub nBlockAlign: u16,
pub wBitsPerSample: u16,
pub cbSize: u16,
}
#[repr(C, packed(1))]
pub struct ADPCMCOEFSET {
pub iCoef1: i16,
pub iCoef2: i16,
}
#[repr(C, packed(1))]
pub struct ADPCMWAVEFORMAT {
pub wfx: WAVEFORMATEX,
pub wSamplesPerBlock: u16,
pub wNumCoef: u16,
pub aCoef: [ADPCMCOEFSET; 1],
}import "golang.org/x/sys/windows"
type WAVEFORMATEX struct {
wFormatTag uint16
nChannels uint16
nSamplesPerSec uint32
nAvgBytesPerSec uint32
nBlockAlign uint16
wBitsPerSample uint16
cbSize uint16
}
type ADPCMCOEFSET struct {
iCoef1 int16
iCoef2 int16
}
type ADPCMWAVEFORMAT struct {
wfx WAVEFORMATEX
wSamplesPerBlock uint16
wNumCoef uint16
aCoef [1]ADPCMCOEFSET
}type
WAVEFORMATEX = packed record
wFormatTag: Word;
nChannels: Word;
nSamplesPerSec: DWORD;
nAvgBytesPerSec: DWORD;
nBlockAlign: Word;
wBitsPerSample: Word;
cbSize: Word;
end;
ADPCMCOEFSET = packed record
iCoef1: Smallint;
iCoef2: Smallint;
end;
ADPCMWAVEFORMAT = packed record
wfx: WAVEFORMATEX;
wSamplesPerBlock: Word;
wNumCoef: Word;
aCoef: array[0..0] of ADPCMCOEFSET;
end;const WAVEFORMATEX = extern struct {
wFormatTag: u16,
nChannels: u16,
nSamplesPerSec: u32,
nAvgBytesPerSec: u32,
nBlockAlign: u16,
wBitsPerSample: u16,
cbSize: u16,
};
const ADPCMCOEFSET = extern struct {
iCoef1: i16,
iCoef2: i16,
};
const ADPCMWAVEFORMAT = extern struct {
wfx: WAVEFORMATEX,
wSamplesPerBlock: u16,
wNumCoef: u16,
aCoef: [1]ADPCMCOEFSET,
};type
WAVEFORMATEX {.packed.} = object
wFormatTag: uint16
nChannels: uint16
nSamplesPerSec: uint32
nAvgBytesPerSec: uint32
nBlockAlign: uint16
wBitsPerSample: uint16
cbSize: uint16
ADPCMCOEFSET {.packed.} = object
iCoef1: int16
iCoef2: int16
ADPCMWAVEFORMAT {.packed.} = object
wfx: WAVEFORMATEX
wSamplesPerBlock: uint16
wNumCoef: uint16
aCoef: array[1, ADPCMCOEFSET]align(1)
struct WAVEFORMATEX
{
ushort wFormatTag;
ushort nChannels;
uint nSamplesPerSec;
uint nAvgBytesPerSec;
ushort nBlockAlign;
ushort wBitsPerSample;
ushort cbSize;
}
align(1)
struct ADPCMCOEFSET
{
short iCoef1;
short iCoef2;
}
align(1)
struct ADPCMWAVEFORMAT
{
WAVEFORMATEX wfx;
ushort wSamplesPerBlock;
ushort wNumCoef;
ADPCMCOEFSET[1] aCoef;
}HSP用 定義
HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; ADPCMWAVEFORMAT サイズ: 26 バイト(x64)
dim st, 7 ; 4byte整数×7(構造体サイズ 26 / 4 切り上げ)
; wfx : WAVEFORMATEX (+0, 18byte) varptr(st)+0 を基点に操作(18byte:入れ子/配列)
; wSamplesPerBlock : WORD (+18, 2byte) wpoke st,18,値 / 値 = wpeek(st,18)
; wNumCoef : WORD (+20, 2byte) wpoke st,20,値 / 値 = wpeek(st,20)
; aCoef : ADPCMCOEFSET (+22, 4byte) varptr(st)+22 を基点に操作(4byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global WAVEFORMATEX, pack=1
#field short wFormatTag
#field short nChannels
#field int nSamplesPerSec
#field int nAvgBytesPerSec
#field short nBlockAlign
#field short wBitsPerSample
#field short cbSize
#endstruct
#defstruct global ADPCMCOEFSET, pack=1
#field short iCoef1
#field short iCoef2
#endstruct
#defstruct global ADPCMWAVEFORMAT, pack=1
#field WAVEFORMATEX wfx
#field short wSamplesPerBlock
#field short wNumCoef
#field ADPCMCOEFSET aCoef 1
#endstruct
stdim st, ADPCMWAVEFORMAT ; NSTRUCT 変数を確保
st->wSamplesPerBlock = 100
mes "wSamplesPerBlock=" + st->wSamplesPerBlock