miniaudio/ports/engine_effects

Code

engine_effects.odin ¶
65 linesSource

1package main
2
3import "base:runtime"
4import "core:fmt"
5import "core:os"
6import ma "vendor:miniaudio"
7
8DELAY_IN_SECONDS :: 0.2
9DECAY :: 0.25
10
11main :: proc() {
12	args := runtime.args__
13	if len(args) < 2 {
14		fmt.eprintfln("No input file.")
15		os.exit(-1)
16	}
17
18	engine: ma.engine
19	result := ma.engine_init(nil, &engine)
20	if result != .SUCCESS {
21		fmt.eprintfln("Failed to initialize audio engine.")
22		os.exit(-2)
23	}
24
25	channels := ma.engine_get_channels(&engine)
26	sample_rate := ma.engine_get_sample_rate(&engine)
27	delay_in_frames := u32(f32(sample_rate) * DELAY_IN_SECONDS)
28	delay_node_config := ma.delay_node_config_init(channels, sample_rate, delay_in_frames, DECAY)
29
30	delay_node: ma.delay_node
31	if ma.delay_node_init(ma.engine_get_node_graph(&engine), &delay_node_config, nil, &delay_node) != .SUCCESS {
32		fmt.eprintfln("Failed to initialize delay node.")
33		os.exit(-3)
34	}
35
36	if ma.node_attach_output_bus(cast(^ma.node)&delay_node, 0, ma.engine_get_endpoint(&engine), 0) != .SUCCESS {
37		fmt.eprintfln("Failed to attach delay node to output bus.")
38		os.exit(-4)
39	}
40
41	sound: ma.sound
42	result = ma.sound_init_from_file(&engine, args[1], {}, nil, nil, &sound)
43	if result != .SUCCESS {
44		fmt.eprintfln("Failed to initialize sound \"%s\".", args[1])
45		os.exit(-5)
46	}
47
48	if ma.node_attach_output_bus(cast(^ma.node)&sound, 0, cast(^ma.node)&delay_node, 0) != .SUCCESS {
49		fmt.eprintfln("Failed to attach sound node to output bus.")
50		os.exit(-6)
51	}
52
53	if ma.sound_start(&sound) != .SUCCESS {
54		fmt.eprintfln("Failed to start sound.")
55		os.exit(-7)
56	}
57
58	fmt.printfln("Press Enter to quit...")
59	p: [1]byte
60	os.read(os.stdin, p[:])
61
62	ma.sound_uninit(&sound)
63	ma.delay_node_uninit(&delay_node, nil)
64	ma.engine_uninit(&engine)
65}

Declarations Used 23