Skip to content

Instantly share code, notes, and snippets.

@Xliff
Last active April 28, 2016 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xliff/608addc037f083577da0bb9a75b9a05e to your computer and use it in GitHub Desktop.
Save Xliff/608addc037f083577da0bb9a75b9a05e to your computer and use it in GitHub Desktop.

SOLVED -- See below.

OK. This boggles!

my @buffer;
# Returns float **
my $prebuff_ptr = vorbis_analysis_buffer($vd, READ);
my @pre_buffer := nativecast(CArray[CArray[num32]], $prebuff_ptr);

# Looks like data!
say "PB: {@pre_buffer[0]} / {@pre_buffer[0][0]}";

# Uninterleave.
# cw: I'm sure there's a smarter way to do this in P6...
loop ($i = 0; $i < $bytes/4; $i++) {
  # Same data!
	say "PB1: {@pre_buffer[0]} / {@pre_buffer[0][$i]}";
	
	# No data. Weird!
	say "PB2: {@pre_buffer[0].WHAT} / {@pre_buffer[0][$i].WHAT}";

  # No data! Throws error.
	@pre_buffer[0][$i] = 0;
}

And here's the output.

PB: NativeCall::Types::CArray[num32]<-1248000780> / 0
PB1: NativeCall::Types::CArray[num32]<-1248000780> / 0
Use of uninitialized value of type NativeCall::Types::CArray[num32] in string context
Any of .^name, .perl, .gist, or .say can stringify undefined things, if needed.  in block  at t/04-write-oggvorbis.t line 126
Use of uninitialized value of type Num in string context
Any of .^name, .perl, .gist, or .say can stringify undefined things, if needed.  in block  at t/04-write-oggvorbis.t line 126
PB2:  /
This type cannot unbox to a native number
  in block  at t/04-write-oggvorbis.t line 128
  in block <unit> at t/04-write-oggvorbis.t line 102

Well, when dealing with a NativeCall type on the Left Hand Side (LHS), it is prudent to enforce the type on the RHS.

In my case, this fixed the problem:

@pre_buffer[0][$i] = Num(0);

Thanks to RabidGravy on freenode:#perl6 for the all too simple solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment