Inheritance #
- AudioServer
- CameraServer
- ClassDB
- DisplayServer
- EditorFileSystemDirectory
- EditorInterface
- EditorPaths
- EditorSelection
- EditorUndoRedoManager
- EditorVCSInterface
- Engine
- EngineDebugger
- FramebufferCacheRD
- GDExtensionManager
- Geometry2D
- Geometry3D
- IP
- Input
- InputMap
- JNISingleton
- JSONRPC
- JavaClassWrapper
- JavaScriptBridge
- MainLoop (1)
- Marshalls
- MovieWriter
- NativeMenu
- NavigationMeshGenerator
- NavigationServer2D
- NavigationServer3D
- Node (21)
- OS
- OpenXRExtensionWrapperExtension
- OpenXRInteractionProfileMetadata
- Performance
- PhysicsDirectBodyState2D (1)
- PhysicsDirectBodyState3D (1)
- PhysicsDirectSpaceState2D (1)
- PhysicsDirectSpaceState3D (1)
- PhysicsServer2D (1)
- PhysicsServer2DManager
- PhysicsServer3D (1)
- PhysicsServer3DManager
- PhysicsServer3DRendering
ServerHandler
- ProjectSettings
- RefCounted (121)
- RenderData (2)
- RenderSceneData (2)
- RenderingDevice
- RenderingServer
- ResourceLoader
- ResourceSaver
- ResourceUID
- ScriptLanguage (1)
- ShaderIncludeDB
- TextServerManager
- ThemeDB
- TileData
- Time
- TranslationServer
- TreeItem
- UndoRedo
- UniformSetCacheRD
- WorkerThreadPool
- XRServer
- XRVRS
- AESContext
- AStar2D
- AStar3D
- AStarGrid2D
- AudioEffectInstance (1)
- AudioSample
- AudioSamplePlayback
- AudioStreamPlayback (5)
- CameraFeed
- CharFXTransform
- ConfigFile
- Crypto
- DTLSServer
- DirAccess
- ENetConnection
- EditorContextMenuPlugin
- EditorDebuggerPlugin
- EditorDebuggerSession
- EditorExportPlatform (6)
- EditorExportPlugin
- EditorExportPreset
- EditorFeatureProfile
- EditorFileSystemImportFormatSupportQuery
- EditorInspectorPlugin
- EditorResourceConversionPlugin
- EditorResourcePreviewGenerator
- EditorResourceTooltipPlugin
- EditorSceneFormatImporter (4)
- EditorScenePostImport
- EditorScenePostImportPlugin
- EditorScript
- EditorTranslationParserPlugin
- EncodedObjectAsID
- EngineProfiler
- Expression
- FileAccess
- GLTFObjectModelProperty
- HMACContext
- HTTPClient
- HashingContext
- ImageFormatLoader (1)
- JavaClass
- JavaObject
- JavaScriptObject
- KinematicCollision2D
- KinematicCollision3D
- Lightmapper (1)
- MeshConvexDecompositionSettings
- MeshDataTool
- MultiplayerAPI (2)
- Mutex
- NavigationPathQueryParameters2D
- NavigationPathQueryParameters3D
- NavigationPathQueryResult2D
- NavigationPathQueryResult3D
- Node3DGizmo (1)
- OggPacketSequencePlayback
- OpenXRAPIExtension
- PCKPacker
- PackedDataContainerRef
- PacketPeer (8)
- PhysicsPointQueryParameters2D
- PhysicsPointQueryParameters3D
- PhysicsRayQueryParameters2D
- PhysicsRayQueryParameters3D
- PhysicsShapeQueryParameters2D
- PhysicsShapeQueryParameters3D
- PhysicsTestMotionParameters2D
- PhysicsTestMotionParameters3D
- PhysicsTestMotionResult2D
- PhysicsTestMotionResult3D
- RDAttachmentFormat
- RDFramebufferPass
- RDPipelineColorBlendState
- RDPipelineColorBlendStateAttachment
- RDPipelineDepthStencilState
- RDPipelineMultisampleState
- RDPipelineRasterizationState
- RDPipelineSpecializationConstant
- RDSamplerState
- RDShaderSource
- RDTextureFormat
- RDTextureView
- RDUniform
- RDVertexAttribute
- RandomNumberGenerator
- RegEx
- RegExMatch
- RenderSceneBuffers (2)
- RenderSceneBuffersConfiguration
- Resource (103)
- ResourceFormatLoader
- ResourceFormatSaver
- ResourceImporter (16)
- SceneState
- SceneTreeTimer
- Semaphore
- SkinReference
- StreamPeer (5)
- SurfaceTool
- TCPServer
- TLSOptions
- TextLine
- TextParagraph
- TextServer (1)
- Thread
- TranslationDomain
- TriangleMesh
- Tween
- Tweener (5)
- UDPServer
- UPNP
- UPNPDevice
- WeakRef
- WebRTCPeerConnection (1)
- XMLParser
- XRInterface (4)
- XRPose
- XRTracker (2)
- ZIPPacker
- ZIPReader
- Animation
- AnimationLibrary
- AnimationNode (6)
- AnimationNodeStateMachinePlayback
- AnimationNodeStateMachineTransition
- AudioBusLayout
- AudioEffect (17)
- AudioStream (10)
- BitMap
- BoneMap
- ButtonGroup
- CameraAttributes (2)
- ColorPalette
- Compositor
- CompositorEffect
- CryptoKey
- Curve
- Curve2D
- Curve3D
- EditorNode3DGizmoPlugin
- EditorSettings
- Environment
- Font (3)
- GDExtension
- GLTFAccessor
- GLTFAnimation
- GLTFBufferView
- GLTFCamera
- GLTFDocument (1)
- GLTFDocumentExtension (1)
- GLTFLight
- GLTFMesh
- GLTFNode
- GLTFPhysicsBody
- GLTFPhysicsShape
- GLTFSkeleton
- GLTFSkin
- GLTFSpecGloss
- GLTFState (1)
- GLTFTexture
- GLTFTextureSampler
- Gradient
- Image
- ImporterMesh
- InputEvent (6)
- JSON
- LabelSettings
- LightmapGIData
- Material (9)
- Mesh (4)
- MeshLibrary
- MissingResource
- MultiMesh
- NavigationMesh
- NavigationMeshSourceGeometryData2D
- NavigationMeshSourceGeometryData3D
- NavigationPolygon
- Noise (1)
- Occluder3D (5)
- OccluderPolygon2D
- OggPacketSequence
- OpenXRAction
- OpenXRActionMap
- OpenXRActionSet
- OpenXRBindingModifier (2)
- OpenXRHapticBase (1)
- OpenXRIPBinding
- OpenXRInteractionProfile
- PackedDataContainer
- PackedScene
- PhysicsMaterial
- PolygonPathFinder
- RDShaderFile
- RDShaderSPIRV
- RichTextEffect
- SceneReplicationConfig
- Script (3)
- Shader (1)
- ShaderInclude
- Shape2D (8)
- Shape3D (9)
- Shortcut
- SkeletonModification2D (7)
- SkeletonModificationStack2D
- SkeletonProfile (1)
- Skin
- Sky
- SpriteFrames
- StyleBox (4)
- SyntaxHighlighter (2)
- Texture (3)
- Theme
- TileMapPattern
- TileSet
- TileSetSource (2)
- Translation (1)
- VideoStream (1)
- VideoStreamPlayback
- VisualShaderNode (62)
- VoxelGIData
- World2D
- World3D
- X509Certificate
- AudioStreamGenerator
- AudioStreamInteractive
- AudioStreamMP3
- AudioStreamMicrophone
- AudioStreamOggVorbis
- AudioStreamPlaylist
- AudioStreamPolyphonic
- AudioStreamRandomizer
- AudioStreamSynchronized
- AudioStreamWAV
Table of contents
-
var data: PackedByteArray = PackedByteArray() -
var format = FORMAT_8_BITS -
var loop_begin: int = 0 -
var loop_end: int = 0 -
var loop_mode = LOOP_DISABLED -
var mix_rate: int = 44100 -
var stereo: bool = false -
static func load_from_buffer(options: Dictionary = {}) -> AudioStreamWAV -
static func load_from_file(options: Dictionary = {}) -> AudioStreamWAV -
func save_to_wav(path: String) -> intError -
const FORMAT_8_BITS = 0 enum Format -
const FORMAT_16_BITS = 1 enum Format -
const FORMAT_IMA_ADPCM = 2 enum Format -
const FORMAT_QOA = 3 enum Format -
const LOOP_DISABLED = 0 enum LoopMode -
const LOOP_FORWARD = 1 enum LoopMode -
const LOOP_PINGPONG = 2 enum LoopMode -
const LOOP_BACKWARD = 3 enum LoopMode -
enum Format -
enum LoopMode
AudioStreamWAV #
is_refcounted, is_instantiable, resource, core, not_builtin_classes
Stores audio data loaded from WAV files.
AudioStreamWAV stores sound samples loaded from WAV files. To play the stored sound, use an AudioStreamPlayer (for non-positional audio) or AudioStreamPlayer2D/AudioStreamPlayer3D (for positional audio). The sound can be looped.
This class can also be used to store dynamically-generated PCM audio data. See also AudioStreamGenerator for procedural audio generation.
Members #
var data: PackedByteArray = PackedByteArray()#
Contains the audio data in bytes.
Note: If format is set to FORMAT_8_BITS, this property expects signed 8-bit PCM data. To convert from unsigned 8-bit PCM, subtract 128 from each byte.
Note: If format is set to FORMAT_QOA, this property expects data from a full QOA file.
var format = FORMAT_8_BITS#
Audio format. See Format constants for values.
var loop_begin: int = 0#
The loop start point (in number of samples, relative to the beginning of the stream).
var loop_end: int = 0#
The loop end point (in number of samples, relative to the beginning of the stream).
var loop_mode = LOOP_DISABLED#
The loop mode. See LoopMode constants for values.
var mix_rate: int = 44100#
The sample rate for mixing this audio. Higher values require more storage space, but result in better quality.
In games, common sample rates in use are 11025, 16000, 22050, 32000, 44100, and 48000.
According to the Nyquist-Shannon sampling theorem, there is no quality difference to human hearing when going past 40,000 Hz (since most humans can only hear up to ~20,000 Hz, often less). If you are using lower-pitched sounds such as voices, lower sample rates such as 32000 or 22050 may be usable with no loss in quality.
var stereo: bool = false#
If true, audio is stereo.
Methods #
static func load_from_buffer(options: Dictionary = {}) -> AudioStreamWAV#
Creates a new AudioStreamWAV instance from the given buffer. The buffer must contain WAV data.
The keys and values of options match the properties of ResourceImporterWAV. The usage of options is identical to AudioStreamWAV.load_from_file.
static func load_from_file(options: Dictionary = {}) -> AudioStreamWAV#
Creates a new AudioStreamWAV instance from the given file path. The file must be in WAV format.
The keys and values of options match the properties of ResourceImporterWAV.
Example: Load the first file dropped as a WAV and play it:
@onready var audio_player = $AudioStreamPlayer
func _ready():
get_window().files_dropped.connect(_on_files_dropped)
func _on_files_dropped(files):
if files[0].get_extension() == "wav":
audio_player.stream = AudioStreamWAV.load_from_file(files[0], {
"force/max_rate": true,
"force/max_rate_hz": 11025
})
audio_player.play()func save_to_wav(path: String) -> intError#
Saves the AudioStreamWAV as a WAV file to path. Samples with IMA ADPCM or Quite OK Audio formats can't be saved.
Note: A .wav extension is automatically appended to path if it is missing.
Annotations #
Constants #
const FORMAT_8_BITS = 0 enum Format#
8-bit PCM audio codec.
const FORMAT_16_BITS = 1 enum Format#
16-bit PCM audio codec.
const FORMAT_IMA_ADPCM = 2 enum Format#
Audio is lossily compressed as IMA ADPCM.
const FORMAT_QOA = 3 enum Format#
Audio is lossily compressed as Quite OK Audio.
const LOOP_DISABLED = 0 enum LoopMode#
Audio does not loop.
const LOOP_FORWARD = 1 enum LoopMode#
Audio loops the data between loop_begin and loop_end, playing forward only.
const LOOP_PINGPONG = 2 enum LoopMode#
Audio loops the data between loop_begin and loop_end, playing back and forth.
const LOOP_BACKWARD = 3 enum LoopMode#
Audio loops the data between loop_begin and loop_end, playing backward only.
Constructors #
Enums #
Format#
enum Format {
FORMAT_8_BITS = 0,
FORMAT_16_BITS = 1,
FORMAT_IMA_ADPCM = 2,
FORMAT_QOA = 3,
}LoopMode#
enum LoopMode {
LOOP_DISABLED = 0,
LOOP_FORWARD = 1,
LOOP_PINGPONG = 2,
LOOP_BACKWARD = 3,
}