Greetings,
I have struct with a @staticmethod that creates an instance of itself within that @staticmethod. When I run this code it works! Unfortunately, when running a smoke test on this code (mojo build --emit object Analysis.mojo), I get an error.
Here’s a code snippet. Below that is the error which says that "MFCC does not conform to the traits FFTProcessable & GetFloat64Featurable, however, it does as you can see.
Again, the error only occurs on the smoke test, not in deployment. Any ideas?
Thank you!
Code Excerpt:
struct MFCC(FFTProcessable, GetFloat64Featurable):
"""Mel-Frequency Cepstral Coefficients (MFCC) analysis.
"""
var sr: Float64
var mel_bands: MelBands
var db_bands: List[Float64]
var dct: DCT
var coeffs: List[Float64]
# =================================
# ... many other functions here ...
# =================================
@staticmethod
def buf_analysis(buf: Buffer, chan: Int = 0, start_frame: Int = 0, var num_frames: Int = -1, num_coeffs: Int = 13, num_bands: Int = 40, min_freq: Float64 = 20.0, max_freq: Float64 = 20000.0, fft_size: Int = 1024, hop_size: Int = 512) raises -> List[List[Float64]]:
if num_frames < 0:
num_frames = buf.num_frames - start_frame
mfcc = MFCC(buf.sample_rate, num_coeffs, num_bands, min_freq, max_freq, fft_size)
return MBufAnalysis.fft_process(mfcc, buf, chan, start_frame, num_frames, fft_size, hop_size)
Error:
/Users/ted/dev/MMMAudio/mmm_audio/Analysis.mojo:1161:28: error: invalid call to 'fft_process': l-value of type 'MFCC' cannot be converted to reference of type 'T', argument type 'MFCC' does not conform to trait 'GetFloat64Featurable & FFTProcessable'
return MBufAnalysis.fft_process(mfcc, buf, chan, start_frame, num_frames, fft_size, hop_size)
~~~~~~~~~~~~^~~~~~~~~~~~ ~~~~
Included from /Users/ted/dev/MMMAudio/mmm_audio/__init__.mojo:1:
Included from /Users/ted/dev/MMMAudio/mmm_audio/__init__.mojo:13:
/Users/ted/dev/MMMAudio/mmm_audio/MBufAnalysisBridge.mojo:240:9: note: function declared here
def fft_process[T: GetFloat64Featurable & FFTProcessable,//,input_win: Int = WindowType.hann](mut analyzer: T, buf: Buffer, chan: Int, start_frame: Int, var num_frames: Int, window_size: Int, hop_size: Int) raises -> List[List[Float64]]:
^
mojo: error: failed to parse the provided Mojo source module
Traceback (most recent call last):
File "/Users/ted/dev/MMMAudio/testing_mmm_audio/test_build_mojo_files.py", line 21, in <module>
test_dir("mmm_audio")
~~~~~~~~^^^^^^^^^^^^^
File "/Users/ted/dev/MMMAudio/testing_mmm_audio/test_build_mojo_files.py", line 15, in test_dir
subprocess.run(["mojo", "build", "--emit", "object", mojo_file], check=True)
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ted/dev/MMMAudio/.pixi/envs/default/lib/python3.13/subprocess.py", line 577, in run
raise CalledProcessError(retcode, process.args,
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['mojo', 'build', '--emit', 'object', 'mmm_audio/Analysis.mojo']' returned non-zero exit status 1.