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