@@ -136,7 +136,7 @@ class Peripherals:
136136 """Peripherals Helper Class for the FruitJam Library
137137
138138 :param audio_output: The audio output interface to use 'speaker' or 'headphone'
139- :param safe_volume_limit: The maximum volume allowed for the audio output. Default is 12 .
139+ :param safe_volume_limit: The maximum volume allowed for the audio output. Default is 0.75 .
140140 Using higher values can damage some speakers, change at your own risk.
141141 :param sample_rate: The sample rate to play back audio data in hertz. Default is 11025.
142142 :param bit_depth: The bits per sample of the audio data. Supports 8 and 16 bits. Default is 16.
@@ -150,7 +150,7 @@ class Peripherals:
150150 def __init__ ( # noqa: PLR0913, PLR0912
151151 self ,
152152 audio_output : str = "headphone" ,
153- safe_volume_limit : int = 12 ,
153+ safe_volume_limit : float = 0.75 ,
154154 sample_rate : int = 11025 ,
155155 bit_depth : int = 16 ,
156156 i2c : busio .I2C = None ,
@@ -189,12 +189,12 @@ def __init__( # noqa: PLR0913, PLR0912
189189 else :
190190 self ._audio = None
191191
192- if safe_volume_limit < 1 or safe_volume_limit > 20 :
193- raise ValueError ("safe_volume_limit must be between 1 and 20 " )
192+ if not ( 0.0 <= safe_volume_limit <= 1.0 ) :
193+ raise ValueError ("safe_volume_limit must be between 0.0 and 1.0 " )
194194 self .safe_volume_limit = safe_volume_limit
195195
196196 self .audio_output = audio_output
197- self ._apply_volume (7 )
197+ self ._apply_volume (0.35 )
198198
199199 self ._sd_mounted = False
200200 sd_pins_in_use = False
@@ -321,20 +321,20 @@ def stop_play(self):
321321 self .wavfile .close ()
322322
323323 @property
324- def volume (self ) -> int :
324+ def volume (self ) -> float :
325325 """
326- The volume level of the Fruit Jam audio output. Valid values are 1-20 .
326+ The volume level of the Fruit Jam audio output. Valid values are 0.0 - 1.0 .
327327 """
328328 return self ._volume
329329
330330 @volume .setter
331- def volume (self , volume_level : int ) -> None :
331+ def volume (self , volume_level : float ) -> None :
332332 """
333- :param volume_level: new volume level 1-20
333+ :param volume_level: new volume level 0.0 - 1.0
334334 :return: None
335335 """
336- if not (1 <= volume_level <= 20 ):
337- raise ValueError ("Volume level must be between 1 and 20 " )
336+ if not (0.0 <= volume_level <= 1.0 ):
337+ raise ValueError ("Volume level must be between 0.0 and 1.0 " )
338338
339339 if volume_level > self .safe_volume_limit :
340340 raise ValueError (
@@ -374,14 +374,14 @@ def _apply_audio_output(self, audio_output: str = None) -> None:
374374 self ._dac .headphone_output = self ._audio_output == "headphone"
375375 self ._dac .speaker_output = self ._audio_output == "speaker"
376376
377- def _apply_volume (self , volume_level : int = None ) -> None :
377+ def _apply_volume (self , volume_level : float = None ) -> None :
378378 """
379379 Map the basic volume level to a db value and set it on the DAC.
380380 """
381381 if volume_level is not None :
382382 self ._volume = volume_level
383383 if self ._dac is not None :
384- db_val = map_range (self ._volume , 1 , 20 , - 63 , 23 )
384+ db_val = map_range (self ._volume , 0.0 , 1.0 , - 63 , 23 )
385385 self ._dac .dac_volume = db_val
386386
387387 def deinit (self ) -> None :
0 commit comments