SmartSound One and T5837 eval record problem

By mohandmoussace… , 7 December 2023

I’m working with the SmartSound one development board, with the T5837 eval. When I record with Audacity or in python the microphone does not record the entire track that I play. For example I play a frequency sweep from 20Hz to 8000Hz in 10 seconds. The microphone does not record the entire sweep, it cuts at a certain frequency which changes each time. it's as if there was a noise reduction function that activates and deactivates.

you can find my python code and the graph of the audio recording attached, at the top of the graph, the excitation signal (the sweep) that I send and at the bottom is what the microphone recorded.

mohandmoussace…

2 years 3 months ago

I'm not allowed to upload my python file there it is:

import sounddevice as sd
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from scipy.signal import chirp

# Spécifiez le périphérique audio externe
recorded_data = []
device_id_input = 2 # Remplacez 0 par l'ID de votre périphérique audio externe pour l'entrée
device_id_output = None # Laissez-le à None pour utiliser le périphérique par défaut pour la sortie audio

# Spécifiez les paramètres d'enregistrement et de lecture
duration = 10 # Durée de l'enregistrement et de la lecture en secondes
sample_rate = 48000 # Taux d'échantillonnage en Hz

# Générez un sweep audio de 20 Hz à 8 kHz
start_freq = 20
end_freq = 8000
time_array = np.linspace(0, duration, int(sample_rate * duration), endpoint=False)
t = np.linspace(0, duration, len(time_array), endpoint=False)
sweep_signal = chirp(t, f0=start_freq, f1=end_freq, t1=duration, method='linear')

# Fonction de rappel pour l'enregistrement
def callback(indata, outdata, frames, time, status):
if status:
print(f"Error: {status}")
recorded_data.extend(indata[:, 0]) # Utilisez une seule voie pour simplifier le tracé

# Enregistrez les données audio avec le sweep et jouez le son en même temps
with sd.Stream(device=(device_id_input, device_id_output), channels=2, callback=callback, samplerate=sample_rate):
sd.play(sweep_signal, samplerate=sample_rate)
sd.wait()

print("Enregistrement terminé.")

# Assurez-vous que tous les tableaux ont la même longueur
min_length = min(len(time_array), len(recorded_data), len(t), len(sweep_signal))
time_array = time_array[:min_length]
recorded_data = recorded_data[:min_length]
t = t[:min_length]
sweep_signal = sweep_signal[:min_length]

sd.play(recorded_data, sample_rate)
sd.wait() # Attendre la fin de la lecture

# Créer un DataFrame avec les données
df = pd.DataFrame({'Time': time_array, 'Recorded Data': recorded_data, 'Sweep Signal': sweep_signal})

# Enregistrer le DataFrame dans un fichier CSV
df.to_csv('enregistrement_audio.csv', index=False)

# Tracer les données enregistrées en fonction du temps
plt.subplot(2, 1, 1)
plt.plot(t, sweep_signal)
plt.title('Signal d''Excitation Utilisé (mV)')

plt.subplot(2, 1, 2)
plt.plot(time_array, recorded_data)
plt.title('Enregistrement Audio en fonction du temps')
plt.xlabel('Temps (secondes)')
plt.ylabel('Amplitude')
plt.tight_layout()
plt.show()

phpbb Post ID
45432
phpbb Topic ID
45430