-
Notifications
You must be signed in to change notification settings - Fork 8
/
sample_vgmplay.py
43 lines (36 loc) · 1005 Bytes
/
sample_vgmplay.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
# license:BSD-3-Clause
#
# VGM Play Example
#
import pygame
from wasm.chipstream import ChipStream
# VGM instance index
VGM_INDEX = 0
# Output sampling rate settings
SAMPLING_RATE = 44100
SAMPLING_CHUNK_SIZE = 4096
# Sound device init (signed 16bit)
pygame.mixer.pre_init(frequency=SAMPLING_RATE, size=-16, channels=2, buffer=SAMPLING_CHUNK_SIZE)
pygame.init()
# Create Wasm instance
chip_stream = ChipStream()
# Setup VGM
header, gd3 = chip_stream.create_vgm_instance(VGM_INDEX, "./vgm/ym2612.vgm", SAMPLING_RATE, SAMPLING_CHUNK_SIZE)
# Print VGM meta
print(header)
print(gd3)
# Play
while chip_stream.vgm_play(VGM_INDEX) == 0:
# Get sampling referance
s16le = chip_stream.vgm_get_sampling_ref(VGM_INDEX)
# Sounds
sample = pygame.mixer.Sound(buffer=s16le)
pygame.mixer.Sound.play(sample)
# Wait pygame mixer
while pygame.mixer.get_busy() == True:
pass
# PyGame quit
pygame.quit()
# Drop instance
chip_stream.drop_vgm_instance(VGM_INDEX)