Select and cut multiple sections of data describing a timewave

Hello. I am looking to calculate the amplitudes for several sections of a timewave. The sections correspond to selections within a selection table, however I can only seem to use one selection per file. How may I be able to add multiple selections (more than one from= ..., to=...). Here is the code that works for one selection, how may I be able to add all of the selections within the selection table? (Hope that makes sense its hard to describe).

high_amp4 <-
readWave("X:/childs_group1/ggm_audio/3.survey_files/San Juan_5E8E4960.WAV") %>%
cutw(., f= 48000, channel=1, from = 1161.006667, to = 1162.006667, choose = FALSE,
plot = FALSE, marks = FALSE, output="wave") %>%
env(., f= 48000, channel = 1, envt = "abs",
msmooth = NULL, ksmooth = NULL, ssmooth = NULL,
asmooth = NULL,
fftw = FALSE, norm = FALSE,
plot = TRUE, k = 1, j = 1)

Hi,

Welcome to the RStudio community!

Next time when you make a post, try to create a reprex, that way it'll be more likely that folk will answer your question :slight_smile: A reprex consists of the minimal code and data needed to recreate the issue/question you're having. You can find instructions how to build and share one here:

In this case I used a dataset that comes with the seewave package to showcase the solution (which I hope is the solution you are looking for)

library(tuneR)
library(seewave)
library(dplyr)

#Get some data
data(tico)

#Full data plot
env(tico, f= 22050, channel = 1, envt = "abs",
    msmooth = NULL, ksmooth = NULL, ssmooth = NULL,
    asmooth = NULL,
    fftw = FALSE, norm = FALSE,
    plot = TRUE, k = 1, j = 1)

#Set the cuts
cuts = data.frame(
  from = c(0.1, 0.5),
  to = c(0.2, 0.8)
)

#Paste the cuts together and plot
data = apply(cuts, 1, function(cut){
  tico %>% 
    cutw(f=22050, from = cut[1], to = cut[2], choose = FALSE,
         plot = FALSE, marks = FALSE, output="wave")
}, simplify = F) %>% do.call(rbind, .) %>%
  env(., f= 22050, channel = 1, envt = "abs",
      msmooth = NULL, ksmooth = NULL, ssmooth = NULL,
      asmooth = NULL,
      fftw = FALSE, norm = FALSE,
      plot = TRUE, k = 1, j = 1)

Created on 2022-03-10 by the reprex package (v2.0.1.9000)

Hope this helps,
PJ

1 Like

Thank you very much I'll give it a go! Looks like it should work!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.