Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mediaComp/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def writeFramesToDirectory(movie: "Movie", directory: str = ...) -> None: ...
def samplesToSound(samples: any) -> "Sound": ...
def makeSound(filename: str) -> "Sound": ...
def makeEmptySound(numSamples: int, samplingRate: int = ..., filename: str = ...) -> "Sound": ...
def makeEmptySoundBySeconds(seconds: int, samplingRate: int) -> "Sound": ...
def makeEmptySoundBySeconds(seconds: int, samplingRate: int = ...) -> "Sound": ...
def duplicateSound(sound: "Sound") -> "Sound": ...
def getSamples(sound: "Sound") -> "Samples": ...
def soundTool(sound: "Sound") -> None: ...
Expand Down
2 changes: 1 addition & 1 deletion src/mediaComp/core/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def getPixelAt(picture, x, y) -> Pixel:
print("getPixelAt(picture,x,y): y (= {}) is less than {} or bigger than the height (= {})".format(y, Picture._PictureIndexOffset, getHeight(picture) - 1 + Picture._PictureIndexOffset))
raise ValueError

return picture.getPixel(x - Picture._PictureIndexOffset, y - Picture._PictureIndexOffset)
return picture.getPixelAt(x - Picture._PictureIndexOffset, y - Picture._PictureIndexOffset)


def setRed(pixel, value) -> None:
Expand Down
4 changes: 2 additions & 2 deletions src/mediaComp/core/sound.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def setSampleValueAt(sound, index, value) -> None:
if index > getNumSamples(sound) - 1 + Sound._SoundIndexOffset:
print("You are trying to access the sample at index: " + str(index) + ", but the last valid index is at " + str(getNumSamples(sound) - 1 + Sound._SoundIndexOffset))
raise ValueError
sound.setSampleValue(index - Sound._SoundIndexOffset, int(value))
sound.setSampleValueAt(index - Sound._SoundIndexOffset, int(value))


def getSampleValueAt(sound, index) -> int:
Expand All @@ -156,7 +156,7 @@ def getSampleValueAt(sound, index) -> int:
if index > getNumSamples(sound) - 1 + Sound._SoundIndexOffset:
print("You are trying to access the sample at index: " + str(index) + ", but the last valid index is at " + str(getNumSamples(sound) - 1 + Sound._SoundIndexOffset))
raise ValueError
return sound.getSampleValue(index - Sound._SoundIndexOffset)
return sound.getSampleValueAt(index - Sound._SoundIndexOffset)


def setSampleValue(sample, value) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/mediaComp/models/Picture.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def setBasicPixel(self, x, y, rgb):
col = Color(rgb[0], rgb[1], rgb[2])
self.getPixel(x,y).setColor(col)

def getPixel(self, x, y):
def getPixelAt(self, x, y):
"""Return the pixel at specified coordinates

Parameters
Expand Down
48 changes: 8 additions & 40 deletions src/mediaComp/models/Sound.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,26 +254,8 @@ def getSamples(self):
samples.append(SoundSample(self, i))
return samples

def getSampleValueAt(self, index):
"""Get the sample at the passed index and handle any SoundExceptions

Parameters
----------
index : int
the desired index

Returns
-------
int
the sample value
"""
try:
value = self.getSampleValue(index)
except:
raise(IndexError("The index {} is not valid for this sound".format(index)))
return value

def getSampleValue(self, frameNum):
def getSampleValueAt(self, index):
"""Sets the value of the sample at the indicated frame

If this is a mono sound, obtains the single sample contained
Expand All @@ -282,15 +264,15 @@ def getSampleValue(self, frameNum):

Parameters
----------
frameNum : int
index : int
the index of the frame to access

Returns
-------
int
integer representation of the bytes contained within frame
"""
n = frameNum * self.sampleWidth * self.numChannels
n = index * self.sampleWidth * self.numChannels
m = n + self.sampleWidth
return int.from_bytes(self.buffer[n:m], byteorder='little', signed=True)

Expand All @@ -309,7 +291,7 @@ def getLeftSample(self, frameNum):
"""
if not self.isStereo():
print("Sound is not stereo, cannot access left value")
return self.getSampleValue(frameNum)
return self.getSampleValueAt(frameNum)

def getRightSample(self, frameNum):
"""Obtains the right sample contained at the specified frame
Expand Down Expand Up @@ -398,22 +380,8 @@ def setFrame(self, frameNum, frame):
for i in range(self.sampleWidth):
self.buffer[frameNum * self.sampleWidth + i] = frame[i]

def setSampleValueAt(self, index, value):
"""Method to set the sample value at the specified index

Parameters
----------
index : int
the index
value : int or float
the new value
"""
try:
self.setSampleValue(index, int(value))
except:
raise(IndexError("The index {} is not valid for this sound".format(index)))

def setSampleValue(self, frameNum, value):
def setSampleValueAt(self, index, value):
"""Sets the value of the sample found at the specified frame

If this sound has more than one channel, then we default to setting
Expand All @@ -422,12 +390,12 @@ def setSampleValue(self, frameNum, value):

Parameters
----------
frameNum : int
index : int
the index of the frame where the sample should be changed
value : int
the new sample value
"""
n = frameNum * self.sampleWidth * self.numChannels
n = index * self.sampleWidth * self.numChannels
m = n + self.sampleWidth
value = max(min(value, self.MAX_POS), self.MAX_NEG)
self.buffer[n:m] = value.to_bytes(self.sampleWidth,
Expand All @@ -447,7 +415,7 @@ def setLeftSample(self, frameNum, value):
if not self.isStereo():
print("Sound is not stereo, cannot set left value")
else:
self.setSampleValue(frameNum, value)
self.setSampleValueAt(frameNum, value)

def setRightSample(self, frameNum, value):
"""Set the right sample value in a stereo sample
Expand Down