diff --git a/.github/workflows/rhub.yaml b/.github/workflows/rhub.yaml index 78afa72..0c7b37e 100644 --- a/.github/workflows/rhub.yaml +++ b/.github/workflows/rhub.yaml @@ -23,9 +23,6 @@ on: description: 'Unique ID. You can leave this empty now.' type: string -env: - THIS_IS_RHUB: yes - jobs: setup: diff --git a/DESCRIPTION b/DESCRIPTION index f55f7a7..1882aa6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ProTrackR2 Title: Manipulate and Play 'ProTracker' Modules -Version: 0.0.6.0011 +Version: 0.0.6.0012 Authors@R: c( person("Pepijn", "de Vries", role = c("aut", "cre"), email = "pepijn.devries@outlook.com", diff --git a/NEWS.md b/NEWS.md index 96cfb7c..fb38b0f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -ProTrackR2 v0.0.6.0011 +ProTrackR2 v0.0.6.0012 ------------- * Implemented `as_pt2cell()` and `as_pt2celllist()` diff --git a/R/pattern.R b/R/pattern.R index c64e0c4..e317781 100644 --- a/R/pattern.R +++ b/R/pattern.R @@ -16,7 +16,8 @@ pt2_pattern <- function(mod, i, ...) { structure( list(mod = mod, i = as.integer(i)), class = "pt2pat" - ) + ) |> + as.raw.pt2pat(compact = TRUE) } #' Create a new ProTracker pattern diff --git a/R/samples.R b/R/samples.R index 7e231b9..608b2ab 100644 --- a/R/samples.R +++ b/R/samples.R @@ -18,7 +18,8 @@ pt2_sample <- function(mod, i, ...) { structure( list(mod = mod, i = as.integer(i)), class = "pt2samp" - ) + ) |> + as.raw() } #' @rdname mod_info diff --git a/data-raw/DATASET.R b/data-raw/DATASET.R index db8a4dd..6179a95 100644 --- a/data-raw/DATASET.R +++ b/data-raw/DATASET.R @@ -19,10 +19,11 @@ if (!requireNamespace("ProTrackR")) { dur2 <- c(dur2, as.numeric(endtime - starttime, "secs")) } mean(dur1)/mean(dur2) - ProTrackR2::pt2_write_sample(mod2$samples[[1]], "data-raw/test-sample.wav") - ProTrackR2::pt2_write_sample(mod2$samples[[1]], "data-raw/test-sample.iff") if (requireNamespace("av")) { - samp <- av::read_audio_bin("data-raw/test-sample.wav") - av::av_audio_convert("data-raw/test-sample.wav", "data-raw/test-sample.aiff") + tempsmp <- tempfile(fileext = ".wav") + pt2_write_sample(mod2$samples[[1]], tempsmp) + samp <- av::read_audio_bin(tempsmp) + av::av_audio_convert( + tempsmp, "data-raw/test-sample.aiff", format = "u8") } } diff --git a/data-raw/test-sample.aiff b/data-raw/test-sample.aiff index f410032..04e05ed 100644 Binary files a/data-raw/test-sample.aiff and b/data-raw/test-sample.aiff differ diff --git a/data-raw/test-sample.iff b/data-raw/test-sample.iff deleted file mode 100644 index 9634c58..0000000 Binary files a/data-raw/test-sample.iff and /dev/null differ diff --git a/data-raw/test-sample.wav b/data-raw/test-sample.wav deleted file mode 100644 index 4f2d493..0000000 Binary files a/data-raw/test-sample.wav and /dev/null differ diff --git a/src/samp_io.cpp b/src/samp_io.cpp index 39018fc..0801a14 100644 --- a/src/samp_io.cpp +++ b/src/samp_io.cpp @@ -54,13 +54,17 @@ raws sample_file_format_(SEXP input, std::string file_type) { if (file_type == "IFF") { // IFF file size - // FORM + 8SVX + VHDR + 20 + NAME + namelen + ANNO + ProTrackR2 + BODY + samplelen - uint32_t file_size = 16 * 4 + 8 + 20 + 10 + sampleLength + (sampleLength & 1); + // FORM + 8SVX + VHDR + 20 + (NAME + namelen) + ANNO + ProTrackR2 + BODY + samplelen + // 6 chunk headers of which 5 have also length 6 * 4 + 5 * 4 + // VHDR always has 20 bytes + // ANNO always has 10 bytes + // NAME and BODY have variable length + uint32_t file_size = 6 * 4 + 5 * 4 + 20 + 10 + sampleLength + (sampleLength & 1); if (namelen > 0) { - file_size += 16 + (namelen + (namelen&1)); + file_size += (namelen + (namelen&1)); } - int32_t align = ((uint32_t)(file_size/4))*4; + int32_t align = ((uint32_t)(file_size/2))*2; writable::raws output((R_xlen_t)align); uint8_t * buffer = (uint8_t *)RAW(as_sexp(output)); diff --git a/tests/testthat/test_io.R b/tests/testthat/test_io.R index 3b18b11..f7ed59a 100644 --- a/tests/testthat/test_io.R +++ b/tests/testthat/test_io.R @@ -1,6 +1,9 @@ mod <- pt2_read_mod(pt2_demo()) sample <- pt2_sample(mod, 0L) -smpfile <- tempfile(fileext = ".raw") +smpfile_raw <- tempfile(fileext = ".raw") +smpfile_iff <- tempfile(fileext = ".iff") +smpfile_wav <- tempfile(fileext = ".wav") +smpfile_aiff <- "https://github.com/pepijn-devries/ProTrackR2/blob/master/data-raw/test-sample.aiff" test_that("Writing a mod works", { expect_no_error({ @@ -10,12 +13,17 @@ test_that("Writing a mod works", { test_that("Writing raw samples will warn user", { expect_warning({ - pt2_write_sample(sample, smpfile) + pt2_write_sample(sample, smpfile_raw) + pt2_write_sample(sample, smpfile_iff) + pt2_write_sample(sample, smpfile_wav) }) }) test_that("Reading sample works", { expect_no_error({ - pt2_read_sample(smpfile) + samp_raw <- pt2_read_sample(smpfile_raw) + samp_iff <- pt2_read_sample(smpfile_iff) + samp_wav <- pt2_read_sample(smpfile_wav) + samp_aiff <- pt2_read_sample(smpfile_aiff) }) }) diff --git a/tests/testthat/test_render.R b/tests/testthat/test_render.R index e9139f2..897e961 100644 --- a/tests/testthat/test_render.R +++ b/tests/testthat/test_render.R @@ -1,7 +1,8 @@ mod <- pt2_read_mod(pt2_demo()) test_that("Module renders as expected", { - skip_if(Sys.getenv("THIS_IS_RHUB") == "yes", "Skip this test on RHUB as the `av` package leaks memory") + skip_if(grepl("valgrind", Sys.getenv("CHECK_ARGS", ""), ignore.case = TRUE), + "Skip this test on RHUB as the `av` package leaks memory") skip_on_cran() skip_if_not_installed("av") snap <- "intro.mp3"