<commit_before>package safe.audio

import safe.math._
import Window._
import FFT._
import MFCC._
import PowerSpectrum._

import scala.util._
import scala.concurrent._
import duration._
import util._

import ExecutionContext.Implicits.global

object AudioTest extends App {
  
  val start = System.currentTimeMillis()
  
  val file = new java.io.File("C:/dev/projects/school/UCCS-MIR/mir/audio/training/notes/acoustic/acoustic_1/A_2.wav")
  
  val channels = AudioStream.read(file.toURI())
  val data = AudioFunctions.merge(channels)
  val step = 1024
  
  val writer = new java.io.FileWriter("C:/temp/A_2_mfcc.futures.csv")
  
  val df = new java.text.DecimalFormat()
  df.setMaximumFractionDigits(4)
  df.setMinimumFractionDigits(4)
  
  val fft2: Seq[Double] => Seq[Complex] = fft
  
  def show(a: Seq[Double]) = a map { df.format(_) }
  
  val extraction = hann andThen fft2 andThen magnitude andThen mfcc(44100, freqMin=0, freqMax=40000)_ andThen show
  
  runSequential()
//  runFutures()
  
  def pad(frame: Seq[Double]) = frame.length match {
    case a if(a == step) => frame
    case n => frame ++ Seq.fill(step - n) { 0.0 }
  }
  
  def runSequential() = {
    data.grouped(step) foreach { frame => 
      val results = extraction(pad(frame))
      writer.write(results.mkString(",") + "\n")
    }
  
    writer.close()
  
    val end = System.currentTimeMillis
    println("Ran in " + (end - start) + " millis")
  }
  
  def runFutures() = {
    def extractionFuture(d: Seq[Double]) = future { extraction(d) }
    
    val results = Future.traverse(data.grouped(step)) { frame => 
      extractionFuture(pad(frame))
    } andThen {
      case Success(itr) => {
        itr foreach { row =>
          writer.write(row.mkString(",") + "\n")<commit_msg>Minor tweak to mfcc params in test<commit_after>package safe.audio

import safe.math._
import Window._
import FFT._
import MFCC._
import PowerSpectrum._

import scala.util._
import scala.concurrent._
import duration._
import util._

import ExecutionContext.Implicits.global

object AudioTest extends App {
  
  val start = System.currentTimeMillis()
  
  val file = new java.io.File("../../../datasets/mir/audio/notes/acoustic/acoustic_1/A_2.wav")
  
  val channels = AudioStream.read(file.toURI())
  val data = AudioFunctions.merge(channels)
  val step = 1024
  
  val writer = new java.io.FileWriter("../../../datasets/mir/out/A_2_mfcc.csv")
  
  val df = new java.text.DecimalFormat()
  df.setMaximumFractionDigits(4)
  df.setMinimumFractionDigits(4)
  
  val fft2: Seq[Double] => Seq[Complex] = fft
  
  def show(a: Seq[Double]) = a map { df.format(_) }
  
  val extraction = hann andThen fft2 andThen magnitude andThen mfcc(44100)_ andThen show
  
  runSequential()
//  runFutures()
  
  def pad(frame: Seq[Double]) = frame.length match {
    case a if(a == step) => frame
    case n => frame ++ Seq.fill(step - n) { 0.0 }
  }
  
  def runSequential() = {
    data.grouped(step) foreach { frame => 
      val results = extraction(pad(frame))
      writer.write(results.mkString(",") + "\n")
    }
  
    writer.close()
  
    val end = System.currentTimeMillis
    println("Ran in " + (end - start) + " millis")
  }
  
  def runFutures() = {
    def extractionFuture(d: Seq[Double]) = future { extraction(d) }
    
    val results = Future.traverse(data.grouped(step)) { frame => 
      extractionFuture(pad(frame))
    } andThen {
      case Success(itr) => {
        itr foreach { row =>
          writer.write(row.mkString(",") + "\n")
{'fraction_non_alphanumeric': 0.13527397260273974, 'fraction_numerical': 0.011986301369863013, 'mean_word_length': 3.080325960419092, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5445623', 'n_tokens_mistral': 1262, 'n_tokens_neox': 1227, 'n_words': 269}