Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d93b598

Browse files
author
tippesi
committed
Testing some stuff
1 parent 7843ca1 commit d93b598

File tree

5 files changed

+59
-10
lines changed

5 files changed

+59
-10
lines changed

‎audio.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __init__(self, filename, chunksize, paudio):
1616

1717
filestream = wave.open(filename, "rb")
1818

19-
self._audiostream = paudio.open(format = paudio.get_format_from_width(filestream.getsampwidth(), False),
19+
self._audiostream = paudio.open(format = paudio.get_format_from_width(filestream.getsampwidth()),
2020
channels = filestream.getnchannels(),
2121
rate = filestream.getframerate(),
2222
output = True)
@@ -50,7 +50,7 @@ def __init__(self, filename, chunksize, paudio):
5050

5151
# Copy byte data to integer list
5252
while(audiodata):
53-
fmt = self._endianness + self._type * int(len(audiodata) / filestream.getsampwidth())
53+
fmt = self._endianness + self._type * int(len(audiodata) / filestream.getsampwidth())
5454
data = struct.unpack(fmt, audiodata)
5555
self._audiodata.extend(data)
5656
audiodata = filestream.readframes(chunksize)
@@ -81,5 +81,6 @@ def update(self):
8181

8282
fmt = self._endianness + self._type * len(subdata)
8383
audiodata = struct.pack(fmt, *subdata)
84+
print(audiodata)
8485
self._audiostream.write(audiodata)
8586
self.progress += readout

‎main.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import audio
22
from postprocessing.volume_postprocessing import VolumePostprocessing
3+
from postprocessing.channel_sine_postprocessing import ChannelSinePostprocessing
34
import pyaudio
45

56
paudio = pyaudio.PyAudio()
67

78
audio = audio.Audio("MenuTheme2_final.wav", 1024, paudio)
89

9-
audio.postprocessing.append(VolumePostprocessing(10.0))
10+
# audio.postprocessing.append(VolumePostprocessing(1.0))
11+
audio.postprocessing.append(ChannelSinePostprocessing(0.1))
1012

1113
while True:
1214
audio.update()
Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
"""
2-
Abstract class for audio postprocessing.
3-
Audio postprocessing is applied per audio stream
4-
after the pitch processing.
2+
3+
This module implements an abstract class for audio postprocessing
4+
55
"""
66
class AudioPostprocessing():
7+
"""Abstract class for audio postprocessing.
8+
9+
Audio postprocessing is applied per audio stream after
10+
the pitch processing.
711
812
"""
9-
10-
"""
13+
1114
def apply(self, data, channels, frequency):
15+
"""Called to apply the post process effect on audio data.
16+
17+
Args:
18+
data (int): The audio samples of the stream. May contain multiple
19+
channels.
20+
channels (int): The number of channels in the audio data.
21+
frequency (int): The frequency of the audio data.
22+
23+
"""
1224
raise NotImplementedError("Class %s doesn't implement apply()" % (self.__class__.__name__))
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from postprocessing.audio_postprocessing import AudioPostprocessing
2+
3+
import time
4+
import math
5+
6+
class ChannelSinePostprocessing(AudioPostprocessing):
7+
8+
def __init__(self, speed = 1.0):
9+
self.starttime = time.clock()
10+
self.speed = speed
11+
12+
def apply(self, data, channels, frequency):
13+
14+
deltatime = (time.clock() - self.starttime) * self.speed
15+
16+
# We want two channels to work with
17+
if channels is not 2:
18+
return
19+
20+
leftVolume = 0.5 * math.sin(deltatime) + 0.5
21+
rightVolume = 1.0 - leftVolume
22+
23+
# print(leftVolume)
24+
25+
for i in range(0, len(data)):
26+
"""
27+
if i % 2:
28+
data[i] = int(float(data[i]) * leftVolume)
29+
else:
30+
data[i] = int(float(data[i]) * rightVolume)
31+
"""
32+
data[i] = data[i] & 255
33+
34+
return data

‎postprocessing/volume_postprocessing.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import postprocessing.audio_postprocessing
1+
from postprocessing.audio_postprocessingimportAudioPostprocessing
22

3-
class VolumePostprocessing(postprocessing.audio_postprocessing.AudioPostprocessing):
3+
class VolumePostprocessing(AudioPostprocessing):
44

55
def __init__(self, volume = 1.0):
66
self.volume = volume

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /